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')
精彩评论