I was found error with 'delta' counting in cck-field.
My explanation below.
I have two node types, "Node A" and "Node B". Each has a node reference to the other, the references are unlimited.
Normal situation, using manual corresponding without CNR-module:
1. Creating Node A1, creating Node B1.
2. Edit Node A1 and set corresponding to Node B1, edit Node B1 and set corresponding to Node A1.
In this case I see in database 2 records for each nodes with 'delta'=0. This mean, that Node A1 and Node B1 have only one link to each other.
3. Creating new Node A2 and set corresponding to existing Node B1.
4. Edit existing Node B1 and set corresponding to new Node A2.
In this case I see in database additional 2 records (total 4) and one of them with 'delta'=1, because Node B1 now have two links to Node A1 and Node A2. Whenever I repeating steps 3 and 4, I see increasing 'delta'-count. If I remote corresponding form Node B, I see correct decreasing 'delta'-count.
When I start using CNR-module, 'delta'-count drive me crazy:
0. I've activated the correspondence Node A to Node B in the admin section (Node A <--> Node B).
1. Creating Node A1, creating Node B1.
2. Edit Node A1 and set corresponding to Node B1. CNR-module makes his work prefect - Node B1 now have link to Node A1.
In database I see two strange records:
Node A1 -> Node B1 with 'delta'=0
Node B1 -> Node A1 with 'delta'=1 (!). It's wrong, because we have only one link and delta must be '0'!
3. Ok, now I'm edit/save Node B1 without any changes and I see that records in database are changed:
Node A1 -> Node B1 with wrong 'delta'=1 (!)
Node B1 -> Node A1 with 'delta'='0' (now it's correct)
4. I'm edit/save Node A1 without any changes and I see result like on step 2:
Node A1 -> Node B1 with 'delta'=0
Node B1 -> Node A1 with wrong 'delta'=1 (!).
5. Creating new Node A2 and set corresponding to existing Node B1. In database:
Node A1 -> Node B1 with 'delta'=0
Node A2 -> Node B1 with 'delta'=0
Node B1 -> Node A1 with 'delta'=1 (!) - wrong count from previous step 4
Node B1 -> Node A2 with 'delta'=2 (!)
6. Now I'm edit/save Node B1 without any changes and I see that records in database are changed:
Node A1 -> Node B1 with 'delta'=1 (!)
Node A2 -> Node B1 with 'delta'=1 (!)
Node B1 -> Node A1 with 'delta'=0
Node B1 -> Node A2 with 'delta'=1
Comment | File | Size | Author |
---|---|---|---|
#19 | corresponding_node_references.crud_.inc_.diff | 1.68 KB | Internetter |
#15 | cnr_fix-delta_672732.patch | 1.24 KB | sirkitree |
Comments
Comment #1
domidc CreditAttribution: domidc commentedYour test are correct. The switching delta count does not have an influence on the functionality of the module. Everything still works, this is probably why it has been undiscovered for so long.
I ll try to include a fix that stops the delta from changing once it is set in next release. Would you by any chance have written a patch for this problem feel fee to add it to this post.
Comment #2
ManyNancy CreditAttribution: ManyNancy commentedThis is a huge problem when using multigroups. For instance, I have a textfield of student next to a student's name. If the delta changes, then the student's name isn't paired with 'student', anymore, and is instead something else, like 'teacher'.
Thanks!
Comment #3
ManyNancy CreditAttribution: ManyNancy commentedI just looked through all my fields, and pretty much all of them are broken in this way.
Comment #4
Flying Drupalist CreditAttribution: Flying Drupalist commentedReally need this fix.
Comment #5
IncrediblyKenzi CreditAttribution: IncrediblyKenzi commentedThere's a secondary effect caused by this behavior.. When I set a specific order of referenced nodes in one node, the order changes when I save any one of those nodes.
Comment #6
domidc CreditAttribution: domidc commentedHere is a patch that solves the problem http://drupal.org/node/73098 It still needs some reviewing so go ahead and review.
Comment #7
drewish CreditAttribution: drewish commenteddomidc, i think you linked to the wrong issue #73098: _quotes_install not being called? is for the Quotes module.
Comment #8
drewish CreditAttribution: drewish commentedOh, perhaps you meant #730986: Refactor to use content module's data APIs?
Comment #9
domidc CreditAttribution: domidc commentedYep, indeed. Wrong url
Comment #10
simon_s CreditAttribution: simon_s commentedPlease publish a new release with fixed delta count bug. Beside that I love this module!
Comment #11
domidc CreditAttribution: domidc commentedThe 3.3 release fixes this issue
Comment #12
simon_s CreditAttribution: simon_s commentedGreat, thanks a lot!!!
Comment #14
sirkitree CreditAttribution: sirkitree commentedI'm afraid I'm seeing this still with 3.3 version. Here is my scenario.
1. A <===> B
2. B is single back to A
3. create node A1
4. create node B1 with ref back to A1
5. view node A1
When you look at A1 it has the noderef to B1 at delta 1 and delta 0 = NULL
Comment #15
sirkitree CreditAttribution: sirkitree commentedThe problem lies in
$referenced_node->{$away_field}[] = array('nid' => $home_node->nid);
. This always assumes that we're adding a new key to$referenced_node->{$away_field}
.This fixes it on insert, but we probably want to do the same checks anywhere we have:
Comment #16
aether CreditAttribution: aether commentedI can confirm that #15 fixes the issue. As sirkitree alludes too it will need to be applied to the update function as well.
Note that this issue also causes views filters that check for "Is empty (NULL)" on the referenced field to behave unpredictably.
Comment #17
heatherann CreditAttribution: heatherann commentedDid this patch cause this new issue where adding a node reference while creating a node causes a double? Issue thread.
Now when we create a new node and simultaneously add a corresponding node reference, it gets created correctly on the new node, but on the other node, it gets added twice: once as delta=1 and once as delta=2 (no data for delta=0).
Comment #18
aether CreditAttribution: aether commented@heatherann
The patch in #15 has not been committed so unless you applied this patch to the module in your Drupal install then your issue stems from something perhaps related but not from this patch. Also, the other issue you reference in your post predates this patch.
Comment #19
Internetter CreditAttribution: Internetter commentedI have found the same bug in my installation. It is worse, because if you have set one node reference field to single, than you you did not see the modules work. References with delta>0 would not be shown in the form.
The patch in #15 works for one direction if the single field is the first I think. There is another situation when CNR tries to update an "away" reference. I have made a small addition to the patch, here it is with the second code change AND the first change.
Comment #20
domidc CreditAttribution: domidc commentedIn version 6.4.dev I m working on. I have put in place checks to counter the NULL interfere with the deltas. I still have to check if it solves this issue.
Comment #21
domidc CreditAttribution: domidc commentedThis patch is included in the 6.4 version which is currently in dev