[Dbix-class] Search using relationships.

brett gardner brett at clientcomm.com.au
Mon Dec 11 01:49:30 GMT 2006


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?

Cheers,
Brett Gardner,
Clientcomm



More information about the Dbix-class mailing list