I'm attempting to avoid an N+1 query by using includes
, but I need to filter out some of the child records. Here's what I have so far:
Column.includes(:tickets).where(board_id: 1, tickets: {sprint_id: 10})
The problem is that only Columns containing Tickets with sprint_id
of 10 are returned. I want to return all Columns with board_id of 1, and pre-fetch tickets only with a sprint_id
of 10, so that column.tickets
is either an empty list of a list of Ticket objects with sprint_id
10.
没有评论:
发表评论