Rails includes with conditions

前端 未结 7 1026
执笔经年
执笔经年 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:31

    For people interested, I tried this where a record attribute was false

    Lead.includes(:contacts).where("contacts.primary" => false).first
    

    and this doesn't work. Somehow for booleans only true works, so I turned it around to include where.not

    Lead.includes(:contacts).where.not("contacts.primary" => true).first
    

    This works perfectly

    0 讨论(0)
提交回复
热议问题