[Dbix-class] Search using relationships.
Matt S Trout
dbix-class at trout.me.uk
Mon Dec 11 09:57:27 GMT 2006
On 11 Dec 2006, at 01:49, brett gardner wrote:
> Is there any reason that you cannot search using relationship
> accessors?
>
> eg
>
> my $respondent =
> $schema->resultset('SurveyRespondent')->find($respondent_id);
>
> my $questions =
> $schema->resultset('SurveyQuestion')->search({foo=>'bar'});
>
> while (my $question = $questions->next){
> my $answer =
> $respondent->search_related('answers',{question_id=>
> $question_id})->next;
> print $answer->display_answer if ($answer);
> }
>
>
> Which means I need to know the foreign keys mapping answers to
> questions. What I would like to be able to do is replace the "my
> $answer ..." line with the following.
>
> my $answer = $respondent->search_related('answers',{question=>
> $question})->next; #question being a relationship defined in the
> SurveyAnswer object.
>
> Is this something that is on the todo list, or has it been looked
> at and deemed to complicated and slow?
It's intended, but it's harder than it looks to implement generally
hence not having been done so far.
--
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for
details.
+ Help us build a better perl ORM: http://dbix-
class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list