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

Support for ActiveRecord::Base.joins #27

Open
mlarraz opened this issue Jun 17, 2015 · 1 comment
Open

Support for ActiveRecord::Base.joins #27

mlarraz opened this issue Jun 17, 2015 · 1 comment

Comments

@mlarraz
Copy link
Contributor

mlarraz commented Jun 17, 2015

With a typical belongs_to association you can use the nice shorthand

class Foo < ActiveRecord::Base
  belongs_to :bar
end

Foo.joins(:bar).to_sql
# => "SELECT \"foos\".* FROM \"foos\" INNER JOIN \"bars\" ON \"bars\".\"bar_id\" = \"foos\".\"foo_id\""

With lookup_for, the association is never registered, and so the query has to be written out

class Foo < ActiveRecord::Base
  lookup_for :bar
end

Foo.joins(:bar)
# => #<ActiveRecord::ConfigurationError: Association named 'bar' was not found on Foo; perhaps you misspelled it?>
@pd
Copy link
Contributor

pd commented Dec 2, 2015

This is related to #11 and my failed PR #18; it's another place where the only way I know of to make this happen is to hack into AR internals. Or, alternatively, pretty sure you could do this in ARel without too much of a headache.

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

No branches or pull requests

2 participants