-
Notifications
You must be signed in to change notification settings - Fork 130
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
Small refactor of relations. #216
Conversation
5ebb14b
to
cf25e06
Compare
cf25e06
to
5308b65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor.
# @return [ nil | Constant ] Type of relation. | ||
def relation_of(field) | ||
meta = meta_of(field) | ||
meta ? meta.relation : nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have a dependency on activesupport, would it be safe to use meta.try(:relation)
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, but it would hide any exception such as the method .relation
no longer exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Too bad we can't rely on Ruby 2.3 safe navigation operator &.
yet.
Here's an example of a CHANGELOG.md entry: * [#216](https://github.com/mongoid/mongoid-history/pull/216): Small refactor of relations - [@dblock](https://github.com/dblock). Generated by 🚫 danger |
Changes Unknown when pulling 5308b65 on dblock:refactor-relations into ** on mongoid:master**. |
1 similar comment
Changes Unknown when pulling 5308b65 on dblock:refactor-relations into ** on mongoid:master**. |
Taking some of the working parts out of #215.
Extracts
increment_current_version
.Simplifies fetching of the relation's class or type of relationship by always looking at
reflect_on_association
and memoizing the result.Collapses
embeds_many_class
andembeds_one_class
intorelation_class_of
.Renames methods from embedded to related so we can continue extending into many-to-many and such.