JOIN ON … AND conditions when eager loading association in ActiveRecord

前端 未结 2 1497
南笙
南笙 2021-01-23 12:58

Please notice, this is not a question about adding a WHERE condition to an association but a rather advanced question about how to alter the JOIN clause when using eager

2条回答
  •  有刺的猬
    2021-01-23 13:08

    EDIT

    This does not solve the problem stated.


    You cannot alter the JOIN generated by calling eager_load like you want. The WHERE clause is your only option, and it has the exact same effect as the condition on your JOIN. Here it is, even if you didn't want it:

    Parent.eager_load(:grades).where("grades.level = 'A+'")
    

提交回复
热议问题