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

僤鯓⒐⒋嵵緔 提交于 2020-01-06 05:35:06

问题


In Rails 5, they have added the ActiveRecord query method left_joins. What's the difference between left_joins and includes? I've always seen includes as a left join.


回答1:


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



来源:https://stackoverflow.com/questions/53414830/whats-the-difference-between-left-joins-and-includes-in-rails-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!