Skip to content

Conversation

mpg-issei-kobayashi
Copy link

No description provided.

## なぜ必要なのか?

has_many の関連付けの場合、preload で関連付けのデータを取得することで、関連元のデータを繰り返し取得しなくてすむため

## 参考

- https://tech.smarthr.jp/entry/2021/11/11/151444
## なぜ必要なのか?

_post.html.erb の post.tags.each の箇所で post ごとに tags のクエリが呼び出され、N+1となっているため
`preload` で `comments` をロード済みであるため、`count` でクエリを発行せずとも、`size` で件数を確認できるため

参考: https://tech.smarthr.jp/entry/2021/11/11/151444
件数を数えるためのクエリを発行しないようにしました
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant