-
-
Notifications
You must be signed in to change notification settings - Fork 232
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
refactor: reflect_on_association
instead _reflections
#3069
Conversation
Code Climate has analyzed commit 72bfc37 and detected 0 issues on this pull request. View more on Code Climate. |
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.
Looks good! Thanks for the refactor!
@@ -188,5 +188,9 @@ def join_record | |||
reflection.through_reflection.klass.find_by(source_foreign_key => @attachment_record.id, | |||
through_foreign_key => @record.id) | |||
end | |||
|
|||
def has_many_reflection? | |||
reflection_class.in? ["HasManyReflection", "HasAndBelongsToManyReflection"] |
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.
I noticed that above some mentions are classes and these are strings.
Is there anything we can do to make them the same or do we have to know when to call as a string and as a class?
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.
Makes sense. There is no reason to use class.name.demodulize.to_s
and check against a string.
Also, let's link the Avo 2 PR as well here for reference. |
@@ -188,5 +188,9 @@ def join_record | |||
reflection.through_reflection.klass.find_by(source_foreign_key => @attachment_record.id, | |||
through_foreign_key => @record.id) | |||
end | |||
|
|||
def has_many_reflection? |
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.
Noice extracting this method! LGTM!
reflect_on_association
instead _reflections
reflect_on_association
instead _reflections
This PR has been merged into Please check the release guide for more information. |
Description
The private
_reflections
API was used to access association reflections in the codebase. This approach relied on internal Rails APIs, which are prone to changes and could lead to compatibility issues in future Rails versions.This PR replaces the use of the private
_reflections
API with the publicreflect_on_association
method. This method is part of the officialActiveRecord::Reflection::ClassMethods
and provides a more robust and future-proof way to access association reflections.