Would this not be solved with adding `votes` to the `includes`? Something like:
```
Post.includes(comments: :votes)
```
Similar stackoverflow: https://stackoverflow.com/a/24397716
```
Post.includes(comments: :votes)
```
Similar stackoverflow: https://stackoverflow.com/a/24397716
If you can count in the database itself it's a big win. Although no doubt your solution is cleaner code.
[1] https://bhserna.com/tools-to-help-you-detect-n-1-queries.htm...