'ActiveRecord - left join on filtered list
I have the following classes:
Parent
has_many :children
Child
belongs_to :parent
belongs_to :other
I want to be able to left join parents and children and also filter the children by the other association. I achieved this by writing a custom join clause:
joins("LEFT JOIN children ON children.parent_id=parents.id AND children.other_id IN (#{ids.join(",")})")
It seems like there should be a more Rails-y way to achieve this that doesn't involve a custom join clause. Any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
