[Dbix-class] search_literal

Matt S Trout dbix-class at trout.me.uk
Mon Sep 24 03:40:41 GMT 2007


On Mon, Sep 24, 2007 at 10:06:01AM +1000, brett gardner wrote:
> Matt S Trout wrote:
> >On Mon, Sep 24, 2007 at 09:04:51AM +1000, brett gardner wrote:
> >  
> >>Well
> >>
> >>Is there anyway to do the following.
> >>
> >>I have a Respondent record, which has a one to many relationship with 
> >>Answer records.
> >>
> >>I want to be able to get a set of Respondents who answered a particular 
> >>way and I first tried do it like
> >>
> >>my $rs = $schema->resultset('Respondent')->search(
> >>	{
> >>		'answers.question_id'=>$foo,
> >>		'answers.answer'=>$bar
> >>	},
> >>	{
> >>		join=>'answers',
> >>	}
> >>);
> >>
> >>
> >>Which works, but when you call search on this resultset again, ie, 
> >>searching withing that subset, it fails eg
> >>
> >>$rs = $rs->search(
> >>	{
> >>    
> > 		'answers_2.question_id'=>$foo_1,
> > 		'answers_2.answer'=>$bar_1,
> >  
> >>	},{
> >>    
> > 		join=> [ 'answers', 'answers' ],
> >  
> >>	}
> >>);
> >>    
> >
> >See the resultset docs for more info about how DBIC handles multiple 
> >aliases.
> >
> (top-posting fixed)
>
> That won't work.  I have a method that receives a resultset of 
> Respondents and performs this sub set search.
> 
> So on occasion I want to be able to pass a resultset through to this 
> method that has already had this sub set search performed on it and then 
> the method does another one.

I think at this stage I'd add a resultset method 'including_answer' or
such like and maintain an internal counter to get the join attr set right
via an extra accessor on the resultset class (or possibly an extra entry
in $self->{attrs})

Useful rule of thumb: If something starts getting hard, you probably wanted
to make it a resultset method with a bit of extra magic in there.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list