-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MONGOID-5274: Issues with #touch method #5202
Conversation
…ouchable_spec.rb 1. On referenced relations with touch: false, calling #touch on document A will touch document B. 2. On embedded relations with touch: false, calling #touch on child document touches its parent (the root cause is different than #2) 3. On embedded relations with touch: true, there is strange behavior where in some cases calling #save! and #destroy on the child does not touch its parent. This works correctly on referenced relations. We should also add more specs for: - embeds_one (calling #touch on parent) - embeds_one -> embedded_in (calling #touch on child) - embeds_many (calling #touch on parent) - referenced has_one - referenced has_many - referenced habtm
@Neilshweky this seems like the kind of investigation you are very good at. |
Hey Johnny! Would have to see what's on the docket and how soon I can take a look at it! I definitely won't be looking at it until at least Monday though... Thanks for the PR, it's super helpful! |
Hey Johnny! I am currently investigating this. A few things...
Hope that helps! I will @ you when I get that other PR up. I'm also updating the JIRA ticket to give a little more info. Thanks for identifying this bug! |
@Neilshweky I'm pretty sure You're certainly welcome to refactor as much as you want, it was just to demonstrate the issues. |
Be sure to look at #5045 by the way... |
Okay, so after a lot more investigation I think I have a grasp of the problem here.
|
Hey @johnnyshields check out this PR #5204 |
@Neilshweky re:
Which comment(s) are you specifically referring to? |
I put some comments on your PR where you had code like:
Which is clearly a bug. Fixing those resolved the first issue. |
@johnnyshields now that #5204 is merged, can you please update this PR and ideally separate it into multiple PRs that each covers a single issue? |
Actually I think this one can be closed. #5204 was just a simplification of this PR |
Okay, that sounds good. |
MONGOID-5274
This PR only contains specs which demonstrate the issues.
Please run spec/mongoid/touchable_spec.rb
On referenced relations with
touch: false
, calling#touch
on document A will touch document B.On embedded relations with
touch: false
, calling#touch
on child document touches its parent (the root cause is different than #2)On embedded relations with
touch: true
, there is strange behavior where in some cases calling #save! and #destroy on the child does not touch its parent. This works correctly on referenced relations.I have raised a PR here #5045 that refactors the
Touchable
module. AFAIK my changes do not break/alter any behavior, but they eliminate unnecessary queries and make the code much easier to read, so I recommend you consider to try debugging with my #5045 version.Note re: #2. When you investigate it, I believe you will find that on embedded childs, we need a way to know if the association with the parent has
touch: true/false
. Note that we have the following:In order to permanently fix the issue, we should add specs to cover all possible relation cases: