rails select and include

前端 未结 5 1304
清歌不尽
清歌不尽 2021-02-19 02:02

Can anyone explain this?

Project.includes([:user, :company])

This executes 3 queries, one to fetch projects, one to fetch users for those proje

5条回答
  •  囚心锁ツ
    2021-02-19 02:20

    I had the same problem with select and includes. For eager loading of associated models I used native Rails scope 'preload' http://apidock.com/rails/ActiveRecord/QueryMethods/preload It provides eager load without skipping of 'select' at scopes chain.

    I found it here https://github.com/rails/rails/pull/2303#issuecomment-3889821

    Hope this tip will be helpful for someone as it was helpful for me.

提交回复
热议问题