views:

20

answers:

1

Lets say I have a Person model and a Opinion model. Opinions belong to Person, a Person has many Opinions. Some people are shy.

I am trying to find a set of opinions where the person is 'not shy' or something along those lines. Is there a way to do this that does not involve finding all people who are not shy and then finding those people's opinions? I would like to do something like the pseudo-code below:

@opinions = Opinion.all.where_owner_person('shy = false')

this might be something obvious I have missed, but I can't seem to come up with the right phrasing in my searches to catch the answer.

thanks in advance.

+2  A: 

This should work:

@opinions = Opinion.joins(:person).where(:people => { :shy => false })

ActiveRecord documentation has some more examples.

Matt
looks like joins needs the singular and where needs the plural so final working is like: `@opinions = Opinion.joins(:person).where(:people => { :shy => false })`
re5et
Thanks, I've corrected my answer.
Matt