3 ms·
In Rails you can make this 3 queries. One to retrieve the board, one to get all the report IDs associated with the board and a third to get all the reports wit
by werdnapk 2y ago
In Rails you can make this 3 queries. One to retrieve the board, one to get all the report IDs associated with the board and a third to get all the reports with the associated report IDs.
An example in Rails would look like:
board = Board.includes(:reports).find(board_id)
- colinbartlett 2y agoI install the Bullet gem in every Rails project because it not only detects these N+1 queries but tells you how to fix them, helping to ensure they never even make it to production. https://github.com/flyerhzm/bullet https://github.com/flyerhzm/bullet
- pjm331 2y agoAs of rails 6.1 you can use active records built in strict_loading to solve this problem as well