mongoose-relationship icon indicating copy to clipboard operation
mongoose-relationship copied to clipboard

Adding parent to existing child in many-many updates child's parent references but not parent's child references

Open paulnebel opened this issue 9 years ago • 5 comments

If I create a parent and child at the same time and set up their relationship everything works fine. However, I've spent several days now trying to work out why, when I add an additional parent to a child in a many-many relationship, the child updates with the parent ID but the parent doesn't update with the child ID. If I add another parent to the child the parent I added last, which didn't reference the child when I added it previously, now does reference the child. It seems as though the parent's child references lag one update behind the child's parent references. Does this sound familiar to you? Is there a way around it? I've spent several days tracking this down only to discover that it's your plugin that's causing it - it makes the plugin unusable unless there's a workaround.

Thanks for your help.

paulnebel avatar Jun 17 '15 15:06 paulnebel

Sorry, please ignore this 'issue'. The fault was in my code, not yours!

paulnebel avatar Jun 18 '15 16:06 paulnebel

And what was your fault, because i have the same problems.

schroffi avatar Jun 18 '15 20:06 schroffi

I put an update function in the wrong place in a nested loop which meant that a category was being mistakenly updated twice. The removal of old parents and the addition of new parents occurs asynchronously and my updates were getting out of step - the new parent was being added and then immediately removed. Once I realised my mistake and put the update function in the correct part of the nested loop I stopped having problems.

I found my error because each time I added a new parent to a child the previously added parent (which did not have a reference to the child at the time it was added) ended up being referenced correctly when the next parent was added. I couldn't understand why the last reference would be updated correctly next time around when it appeared not to be updated correctly the first time so I looked carefully at my code and saw the mistake.

paulnebel avatar Jun 19 '15 07:06 paulnebel

Further testing has shown that this is, actually, a bug. It appeared to be working for me yesterday but is not doing so now. Sorry for the confusion, but it does actually seem to be a bug.

paulnebel avatar Jun 19 '15 13:06 paulnebel

I have this bug too. And after some hours of testing I disable plugin relationship for many-to-many fields.

Alexnder avatar Nov 12 '15 21:11 Alexnder