楷模...
InternalUser
has_many :internal_user_roles
has_many :roles, :through => :internal_user_roles
InternalUserRole
belongs_to :internal_user
belongs_to :role
Role
has_many :internal_user_roles
has_many :internal_users, :through => :internal_user_roles
使用新的 ActiveRecord 查询 API,我如何找到所有InternalUser
具有“ADMIN”角色的 s?
换句话说,我如何生成这个查询......
SELECT
*
FROM
internal_users i, internal_user_roles ir, roles r
WHERE
i.id = ir.internal_user_id
AND
r.id = ir.internal_user_id
AND
r.name = 'ADMIN'