我有两种模式User
和Service
。 User
has_and_belongs_to_many Services
同样适用于Services
:查询有关has_many模型的rails 3
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])
你创建的连接表? –
@Zambon是的,我有一个连接表 –