query related has_many model in rails 3 -


i have 2 models user , service. user has_and_belongs_to_many services same goes services:

class user < activerecord::base   has_and_belongs_to_many :services end  class service < activerecord::base   has_and_belongs_to_many :users end 

i need find users provide selected services. like:

@users = user.where(:services_ids => [2,3,4])

this should work:

user.join(:services).where(:services.id => [2,3,4]).uniq 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -