This returns rows from ccc which is not what you want:
return $_->search({
some_id => { '!=' => undef },
})
->search_related('aaa')
->search_related('bbb')
->search_related('ccc');
...so rather than doing it in a Perly way which returns an array not a resultset, not to mention many more queries than strictly necessary:
return grep {
$_->search_related('aaa')
->search_related('bbb')
->search_related('ccc')->all;
} $self->search({
some_id => { '!=' => undef },
});
...instead do it the DBIC way, which returns a resultset, and is further chainable, etc.:
return $self->search({
'me.some_id' => { '!=' => undef },
'ccc.some_other_id' => { '!=' => undef },
}, {
join => { 'aaa' => { 'bbb' => 'ccc' } }
});
See docs: DBIx/Class/Manual/Joining.pod#COMPLEX_JOINS_AND_STUFF