I'd like to have functionality like this:
$parent->get_grandchildren_by_category({category => 'foo'});
I can do it easily outside of the parent class with a simple chained join:
$schema->resultset('Parent')->search(
{
'me.id' => 62,
'grandchildren.category' => 'foo'
},
{
join => {'children' => 'grandchildren'}
}
);
But inside the parent class I don't have access (and shouldn't) to the schema object.
Inside the parent class I can access $self->children
but that returns a resultset of children, and I'd have to iterate over them to get each one's grandchildren
.
Is there any way I can define this ActiveRecord style?
class Parent < ActiveRecord::Base
has_many :children
has_many :grandchildren, :through => :children
end