Rails includes with conditions

前端 未结 7 1048
执笔经年
执笔经年 2020-12-08 03:33

Is is possible in Rails > 3.2 to add conditions to the join statement generated by the includes method?

Let\'s say I have two models, Person and Note. E

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 04:18

    One way is to write the LEFT JOIN clause yourself by using joins:

    Person.joins('LEFT JOIN "notes" ON "notes"."person_id" = "people.id" AND "notes"."important" IS "t"')
    

    Not pretty, though.

提交回复
热议问题