2021年1月23日星期六

Active Record .includes with where clause

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.

https://stackoverflow.com/questions/65862415/active-record-includes-with-where-clause January 24, 2021 at 01:45AM

没有评论:

发表评论