Skip to content
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

Issues using through option #99

Closed
jwoertink opened this issue Jun 19, 2017 · 0 comments · Fixed by #100
Closed

Issues using through option #99

jwoertink opened this issue Jun 19, 2017 · 0 comments · Fixed by #100

Comments

@jwoertink
Copy link
Contributor

This is loosely along the same lines as #98.

When using the through option, as I defined in the other issue, I would expect to use the plural name of the association like has_many :owners, through: :car_owners. The issue is that this line doesn't singularize that term which would mean it's looking for a foreign_key car_owners_id (unless the foreign key is specified).

Now, if I'm reading this correctly, since the through option is specified here, it will run this code which calls id. In my case, my "through" table has no id field.

Another example for this issue:

schema "facts" do
  has_many :fact_checkers, FactChecker
  has_many :checkers, Checker, through: :fact_checker # this has to be single to work or foreign_key would need to be specified
end

# only has a fact_id and checker_id
schema "fact_checkers" do
   belongs_to :fact, Fact
   belongs_to :checker, Checker
end

schema "checkers" do
   has_many :fact_checkers, FactChecker
   has_many :facts, through: :fact_checker # single again here too
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant