Rails includes with conditions

前端 未结 7 1049
执笔经年
执笔经年 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条回答
  •  旧时难觅i
    2020-12-08 04:13

    Rails 5+ syntax:

    Person.includes(:notes).where(notes: {important: true})
    

    Nested:

    Person.includes(notes: [:grades]).where(notes: {important: true, grades: {important: true})
    

提交回复
热议问题