What's the difference between “left_joins” and “includes” in Rails 5?

后端 未结 1 1823
谎友^
谎友^ 2021-01-23 12:02

In Rails 5, they have added the ActiveRecord query method left_joins. What\'s the difference between left_joins and includes? I\'ve alway

相关标签:
1条回答
  • 2021-01-23 12:34

    includes by default loads the association data in 2 queries just like preload. But with additional references call it switches from using two separate queries to creating a single LEFT OUTER JOIN like left_joins.

    Refs:

    Preload, Eagerload, Includes and Joins

    Making sense of ActiveRecord joins, includes, preload, and eager_load

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