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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

domidc’s picture

Assigned: Unassigned » domidc
Category: bug » task

Your 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.

ManyNancy’s picture

This 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!

ManyNancy’s picture

Priority: Normal » Critical

I just looked through all my fields, and pretty much all of them are broken in this way.

Flying Drupalist’s picture

Really need this fix.

IncrediblyKenzi’s picture

There'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.

domidc’s picture

Here is a patch that solves the problem http://drupal.org/node/73098 It still needs some reviewing so go ahead and review.

drewish’s picture

domidc, i think you linked to the wrong issue #73098: _quotes_install not being called? is for the Quotes module.

drewish’s picture

domidc’s picture

Yep, indeed. Wrong url

simon_s’s picture

Please publish a new release with fixed delta count bug. Beside that I love this module!

domidc’s picture

Status: Active » Fixed

The 3.3 release fixes this issue

simon_s’s picture

Great, thanks a lot!!!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sirkitree’s picture

Version: 6.x-3.2 » 6.x-3.3
Assigned: domidc » Unassigned
Category: task » bug
Status: Closed (fixed) » Active

I'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

sirkitree’s picture

Status: Active » Needs review
FileSize
1.24 KB

The 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:

$referenced_node->{$away_field}[] = array('nid' => $home_node->nid);
aether’s picture

I 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.

heatherann’s picture

Did 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).

aether’s picture

@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.

Internetter’s picture

I 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.

domidc’s picture

In 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.

domidc’s picture

Status: Needs review » Fixed

This patch is included in the 6.4 version which is currently in dev

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.