开发者

rails 3 + active record: how do I do something like stores = Store.User_find_all_by_owner_name("Ted")

I'm having trouble understanding how to do a simple query that combines all the Stores that are owned by all the Users who are named "Ted"

my class User has_many :stores and user.owner_name is the name of the store owner

开发者_开发技巧

my class Store belongs_to :user

users = User.find_all_by_owner_name("Ted") pulls all my users named Ted

But how do I then get all the stores that are owned by that set of users (named Ted)?

I need to get that list as a single record set.


I think this should do it

Store.joins(:user).where('users.owner_name = ?', 'Ted')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜