I have 2 models: Sophead
and SopheadIssue
.
SopheadIssue belongs to Sophead
,
Sophead has many SopheadIssues
(optional).
I want to create a scope on the Sophead model for Sopheads that match EITHER of the 2 conditions:
- The Sophead has no SopheadIssues at all
- The Sophead has no SopheadIssues with a SopheadIssue attribute of (active=true).
At the moment I have tried the following:
scope :no_issue, -> { joins(:sophead_issues).where.not("active = ?", true) }
But this isn't working as it is missing Sopheads without any SopheadIssues.
Any help much appreciated.
Thanks very much!