What's the difference between “includes” and “joins” in ActiveRecord query?

前端 未结 6 1796
名媛妹妹
名媛妹妹 2020-12-15 18:37

What\'s the difference between \"includes\" and \"joins\" in ActiveRecord query? Can anyone explain to me with the following two associated

6条回答
  •  别那么骄傲
    2020-12-15 18:46

    :joins returns read-only objects, :includes does not

    :joins uses inner join, :includes uses outer join.

    the main reason of :includes is eager loading, to avoid the N+1 problem of loading in attributes of each object using a separate query.

提交回复
热议问题