Example.joins(another: :things).where(examples: {status: 'active'}, things: {status: 'required'}).where.not(things: {status: 'unwanted'})
The result from the query above is the same with or without the "where.not".
Things may have different statuses: 'required', 'unwanted' and many others. I must fetch Example records that contain at least one thing with 'required' status, but exclude records that contain one or more thing with 'unwanted' status.
Any help? Thanks!
I can think of this problem to solve using 2 queries. Rails form will be helpful in this case.
then,
Here is the chat conversations which leads to this answer.