Find with two levels has_many

Hello, I have
A has_many B
and B has_many C

B class have a property is_enabled
C class have a property is_enabled

I need to do a eager loading on A B C
while having a condition on B.is_enabled and C.is_enabled

I’ve tried :
A.find(:all, :include => [:B, :C], :conditions => “A.is_enabled = true
AND C.is_enabled = true”)

There’s something wrong with this syntax and I get the error :
Association named ‘C’ was not found; perhaps you misspelled it?

Of course :include => [:B, :C] is wrong, I should be able to write
something like :include => [:B, :include => :C] but I don’t know how to
do…

Do you understand my needs ?

Thanks for your help !!

I’ve tried :
Do you understand my needs ?

Thanks for your help !!

Hi there,

You might want to give A.find(:all, :include => {:B => :C}, :conditions
=>
‘…’) a try.

Cheers,
Marcel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs