-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added reverseKey support for Many relations #92
Conversation
…ning or initializing with an attributes object rather than an AssociatedModel.
Wow...That's one mammoth PR! Thank you and a a happy new year as well! I am going to have to spend some serious time on this before getting back to you...So please hold on! |
Yes of course it'll take some reading. Take your time. And if you have any questions feel free to ask (in this thread or via email). FYI I just pushed one more (last I hope! :) commit to this PR. This closes a hole that I had left open: If you set a
before you've ever created any other zoo, the reverse relation won't exist and the new animal will simply get the raw object as the value of The latest PR lets you fix this in two ways:
Thus:
Let me know if you want me to squash the commits together and issue a clean PR. Cheers |
… value. this is the same issue addressed in dhruvaray#91, but now with a test case
… cleanup. now include a test to verify caching
…n mechanism. also suppress bubbling through a relation and back through its reverse, to avoid combinatorial explosion
@ronen : After spending some time with the code, I thought it would be prudent to refer folks to your repo changes - in our documentation - should they feel the need of auto-reverse relations. The cost of auto-relations has added a lot of incidental complexity (and corner cases) in the library. I yet believe that the extra cost of specifying the reverse relation explicitly (by the application) is well worth the additional complexity which would otherwise get added to the base library if we incorporated this feature. I hope you understand! I would however love to see this branch merged to our repo HEAD. |
@dhruvaray sorry for the delay, i'm currently on (paternity) leave, focusing on non-tech stuff for a while.
to me, the existence of corner cases is why it should be in the library rather than the application; otherwise each application developer would need to find and debug those cases independently.
will try to do that when i get a chance.
doesn't completely sit right to me to maintain a ghost side branch. seems like it'd be candidate for getting out of sync, incompatible changes, etc. perhaps after merging against HEAD will see how simple/complex it gets. |
Hi. Well, since I mouthed off in #51 about how much I wanted reverse keys, I figured I should put my money where my mouth is. So I've taken the liberty of coding up an implementation of reverseKey (for Many relations only).
Here are some notes/documentation. For the sake of discussion, assume a relation of the form
You can add an Animal to a Zoo's "animals" collection from either direction:
You can likewise remove an Animal from a Zoo's "animals" collection from either direction:
No events are sent until the object graph is completely updated. Here's a quick rundown of the events:
(Getting the events right was the trickiest part of the implementation!)
I've included a whole bunch of tests for the new behavior, and have verified that all the old tests still pass. I tried to minimize/localize the impact on the code, and of course to have minimal runtime impact if relationKey is not specified. I've tried it out in my app and it seems to be working well. Hope you like it!
And of course I'm open to suggestions If you think I did anything wrong in terms of functionality or implementation.
Happy new year :)