-
Notifications
You must be signed in to change notification settings - Fork 33
Add support for :through
associations
#630
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
base: main
Are you sure you want to change the base?
Conversation
de3a801
to
62c54e5
Compare
:through
associations
has_one :location, class_name: "Country" | ||
belongs_to :location, class_name: "Country" |
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.
Going off of the schema I'm pretty sure this was incorrectly set up, as I don't see any tests that expect this to be invalid.
62c54e5
to
631ee7e
Compare
end | ||
RUBY | ||
|
||
assert_equal(2, response.size) |
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.
end | ||
RUBY | ||
|
||
assert_equal(2, response.size) |
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.
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.
The Windows failures are unrelated. This makes sense, just added a question about the experience and the structure of the code
through_association_name = node.arguments.arguments | ||
.filter_map { |arg| arg.elements if arg.is_a?(Prism::KeywordHashNode) } | ||
.flatten | ||
.find { |elem| elem.key.value == "through" } | ||
&.value | ||
&.unescaped | ||
handle_association_name(through_association_name) if through_association_name |
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.
Just to understand the intended experience, when going to definition you'd see both the association and the through
association as options, correct?
Also, the node.arguments
return is nilable for when there are no arguments. I think we can restructure this a bit.
- At the top of the
handle_association
method, we can get the arguments and return early if it's nil.
arguments = node.arguments&.arguments
return unless arguments
- Then you can reuse the same arguments array for checking the first argument and the
through
Currently, clicking on the through association name goes to the same file as the association name. I've added explicit support to navigate to the correct through association model file.