I have two models:
class Parent < ActiveRecord::Base
has_many :children
end
class Child < ActiveRecord::Base
belongs_to :parent
end
I want to find all parents AND their children, with conditions on the children only. BUT if the parent has no children that match that criteria, I still want the parent.
I tried this:
Parent.all(:include => :children, :conditions => {'children.some_condition' => 'some_value'})
However this doesn't return parents that have no matching children. I want ALL parents and only the children of those parents that match my condition.
Unfortunately I'm using Rails 2.1.1. I'd like to upgrade but it's not my major priority right now, so consider that a limitation in the possible implementation.
EDIT: Scratch that, just upgraded to 2.3.6, was fairly painless
Any help is greatly appreciated.