Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshuay03
Copy link
Contributor

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.

@joshuay03 joshuay03 requested a review from a team as a code owner July 3, 2025 14:09
@joshuay03 joshuay03 force-pushed the through-association-support branch from de3a801 to 62c54e5 Compare July 3, 2025 14:10
@joshuay03 joshuay03 changed the title Add support for :through associations Add support for :through associations Jul 3, 2025
@joshuay03 joshuay03 moved this to In Progress / Pending Review in Open Source Jul 3, 2025
has_one :location, class_name: "Country"
belongs_to :location, class_name: "Country"
Copy link
Contributor Author

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.

@joshuay03 joshuay03 force-pushed the through-association-support branch from 62c54e5 to 631ee7e Compare July 3, 2025 14:13
end
RUBY

assert_equal(2, response.size)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without patch:
Screenshot 2025-07-03 at 11 52 27 pm

end
RUBY

assert_equal(2, response.size)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without patch:
Screenshot 2025-07-03 at 11 53 04 pm

@vinistock vinistock added the enhancement New feature or request label Jul 16, 2025
Copy link
Member

@vinistock vinistock left a 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

Comment on lines +113 to +119
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
Copy link
Member

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.

  1. 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
  1. Then you can reuse the same arguments array for checking the first argument and the through

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants