Rails active record querying association with 'exists'

后端 未结 4 1910
感动是毒
感动是毒 2020-11-27 03:22

I am working on an app that allows Members to take a survey (Member has a one to many relationship with Response). Response holds the member_id, question_id, and their answe

4条回答
  •  不知归路
    2020-11-27 03:51

    You can also use a subquery:

    members.where(id: Response.select(:member_id))
    

    In comparison to something with includes it will not load the associated models (which is a performance benefit if you do not need them).

提交回复
热议问题