How can I do a LEFT OUTER JOIN using Rails ActiveRecord?

前端 未结 8 1069
终归单人心
终归单人心 2021-02-05 06:42

I don\'t have any ideas. Could you give me any clues (like reference sites). Any help will be appreciated.

Model1: GROUP         


        
8条回答
  •  暖寄归人
    2021-02-05 07:31

    Use a custom joins statement:

    Group.joins("left outer join user_group_cmbs as cmb on groups.id = cmb.group_id")
      .where("cmb.user_id = ?", 1)
    

提交回复
热议问题