-
Notifications
You must be signed in to change notification settings - Fork 21.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
Prevent foreign_key_for? from evaluating all attributes #14140
Prevent foreign_key_for? from evaluating all attributes #14140
Conversation
@@ -232,7 +232,7 @@ def invertible_for?(record) | |||
|
|||
# Returns true if record contains the foreign_key | |||
def foreign_key_for?(record) | |||
record.attributes.has_key? reflection.foreign_key | |||
record.attribute_names.include? reflection.foreign_key |
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 catch. You could actually make use of has_attribute?
which is public api.
@carlosantoniodasilva thanks, changed! |
May you add tests for this? |
@pftg: there's no feature change, nor bugfix. This is "only" a speed improvement. |
@dmathieu thanks |
💖 |
Prevent foreign_key_for? from evaluating all attributes
Thanks. |
Prevent foreign_key_for? from evaluating all attributes
Prevent foreign_key_for? from evaluating all attributes
Attributes should be evaluated lazily if possible (this prevents slow type-casting of date/time/timestamp columns when they are not used).
attributes.has_key?
caused all attributes to be evaluated just to set inverse association record instance.