开发者

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

开发者 https://www.devze.com 2023-03-17 06:50 出处:网络
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\"

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

精彩评论

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

关注公众号