Could I add an association based on another association?

前端 未结 4 554
闹比i
闹比i 2021-01-15 21:41

My User model looks like:

User
   habtm  :Roles


Role
   habtm  :Users


RoleExtension
   belongs_to  :Role

mysql tables:

         


        
4条回答
  •  鱼传尺愫
    2021-01-15 22:09

    user = User.find(1)
    RoleExtension.find(:all, :conditions => ["role_id IN (?)", user.role_ids])
    

    Otherwise you can use nested joins.

提交回复
热议问题