lookup_by icon indicating copy to clipboard operation
lookup_by copied to clipboard

Support for ActiveRecord::Base.joins

Open mlarraz opened this issue 9 years ago • 1 comments

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?>

mlarraz avatar Jun 17 '15 01:06 mlarraz

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.

pd avatar Dec 02 '15 23:12 pd