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

前端 未结 6 1795
名媛妹妹
名媛妹妹 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:51

    :joins joins tables together in sql, :includes eager loads associations to avoid the n+1 problem (where one query is executed to retrieve the record and then one per association which is loaded).

    I suggest you read their sections in Rails Guides to get more info.

提交回复
热议问题