[Dbix-class] modifying join condition in search

Ash Berlin ash_cpan at firemirror.com
Thu Jul 19 11:03:22 GMT 2007


Pedro Melo wrote:
> > Hi,
> >
> > I have a relation defined like this:
> >
> > in Topics.pm:
> >
> > __PACKAGE__->has_many(   watchers   => 'PH::S::Watching',
> > { 'foreign.topic_id' => 'self.id'              });
> >
> > In a search() I need to do a left join between Topics and Watching,
> > but I need to add another statement to the join condition.
> >
> > If I use join => 'watchers',
> >
> > the SQL generated is:
> >
> > ph_topics me LEFT JOIN ph_watchers watchers ON ( watchers.topic_id =
> > me.id )
> >
> > but I need it to be like this:
> >
> > ph_topics me LEFT JOIN ph_watchers watchers ON ( watchers.topic_id =
> > me.id AND watchers.user_id = 5 )
> >
> > (where 5 wlll be a parameter).
> >
> > Before I jump to the 'from' attribute, can this be done with join? I
> > could not figure it out...
> >
> > Best regards,

Why do you need it to be in the join? whats the difference between:

ph_topics me LEFT JOIN ph_watchers watchers ON ( watchers.topic_id =
me.id AND watchers.user_id = ? )

and

ph_topics me LEFT JOIN ph_watchers watchers ON ( watchers.topic_id =
me.id ) WHERE watchers.user_id = 5





More information about the Dbix-class mailing list