我有两个模型User
和Service
。User
has_and_belongs_to_manyServices
同样适用于Services
:
class User < ActiveRecord::Base
has_and_belongs_to_many :services
end
class Service < ActiveRecord::Base
has_and_belongs_to_many :users
end
我需要找到所有提供选定服务的用户。就像是:
@users = User.where(:services_ids => [2,3,4])