Rubytastic
Rubytastic

Reputation: 15501

newbie: activerecord joins ? some help converting sql to activerecord

Im trying to figure out how to do:

Now Im trying to get all the participants from a group where group.id ='1' and where participant.profile.gender = 'x'

How would this convert to active record? I have digged the docs but not a sql guru and not a AR guru at all. anyone can point me in right direction? that would be very helpful to understand how to do this. confused

Upvotes: 1

Views: 161

Answers (1)

Ben Miller
Ben Miller

Reputation: 1484

I think you can do something like

 Participant.where(:group_id => 1).where(:profile=>{:gender=>'x'})

Update: since participant is a join table you would need to change that:

 Participant.where(:group_id => 1).where(:user=>{:profile=>{:gender=>'x'}})

you would also need to add a belongs_to :user to Participant

Upvotes: 1

Related Questions