开发者

Rails, using ActiveRecord to find all rows matching a parent row attribute

I have a class Foo which has_many Bars. Foo has an attribute, some_id. I want to Retrieve all Bar insta开发者_如何学运维nces where the Foo has some_id = N. In SQL this translates into something like:

select * from bar inner join foo on foo.id = bar.foo_id WHERE foo.some_id = N


It would be something like:

Bar.all :joins => :foo, :conditions => {:foos => {:some_id => N}}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜