Skip to content
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

Updating Trackable::association_hash to write through parent. #34

Merged
merged 2 commits into from May 1, 2012

Conversation

tcopple
Copy link

@tcopple tcopple commented Apr 30, 2012

Currently there are cases (on destroy mianly) where an child document
would write it's class name to the association_hash 'name' field. This
happens when it fails to lookup the relationship meta information pertaining to it's
parent OR when the child has been deleted off the parent record before
the destroy history track has been written.

Then if you are trying to use that history track later on, it would fail
the to be able to lookup it's trackable_parent, among other methods,
because it would try to traverse a relationship titled "Comment"
instead of the actual name of teh association, 'comments'.

This fix makes it so a child document doesn't fail to lookup the name of
the relation, when a parent is present, regardless of when the delete
occurs.

Currently there are cases (on destroy mianly) where an child document
would write it's class name to the association_hash 'name' field. This
happens  when it fails to lookup the relationship meta information pertaining to it's
parent OR when the child has been deleted off the parent record before
the destroy history track has been written.

Then if you are trying to use that history track later on, it would fail
the to be able to lookup it's trackable_parent, among other methods,
because it would try to traverse a relationship titled "Comment"
instead of the actual name of teh association, 'comments'.

This fix makes it so a child document doesn't fail to lookup the name of
the relation, when a parent is present, regardless of when the delete
occurs.

inverse = node._parent.reflect_on_association(meta.inverse) if meta
#We prefer to look up associations through the parent record because
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be picky, could you please fix spelling in this comment (exist is misspelled exsist) and add a space after a # :) thx.

@dblock
Copy link
Collaborator

dblock commented May 1, 2012

Good. I'll merge it after the comment fixes. Thanks.

@tcopple
Copy link
Author

tcopple commented May 1, 2012

@dblock Sorry about the typos. Let me know if there's anything else.

@dblock
Copy link
Collaborator

dblock commented May 1, 2012

Merging this, /cc: @aq1018

dblock added a commit that referenced this pull request May 1, 2012
Updating Trackable::association_hash to write through parent.
@dblock dblock merged commit 255ad1c into mongoid:master May 1, 2012
@aq1018
Copy link
Contributor

aq1018 commented May 1, 2012

thanks! @dblock!

@aq1018
Copy link
Contributor

aq1018 commented May 1, 2012

@dblock, are you able to release the gem? I've been caught up in a few projects and getting quite busy lately.

vanboom added a commit to vanboom/mongoid-history that referenced this pull request Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants