Reputation: 755
I have tables a,b. Associated classes
class A < ActiveRecord::Base
has_one :b
end
class B <ActiveRecord::Base
end
b has integer field c.
I want to retrieve all records of A that have a B which has c< 5.
I've tried
A.find(:conditions => (B.c < 5) )
but I get complaints "undefined member c".
What is the best way to accomplish this?
Upvotes: 1
Views: 467
Reputation: 2670
Don't use find. Go ahead with "where"
A.joins(:b).where("b.c < 5")
A.b.where("c < 5")
Upvotes: 1
Reputation: 4097
Try this
A.b.where("c < 5")
dont use the find contions, it is decremented with rails 3
Upvotes: 0