[Dbix-class] modifying join condition in search

Pedro Melo melo at simplicidade.org
Thu Jul 19 09:02:56 GMT 2007


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,
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo at simplicidade.org
Use XMPP!





More information about the Dbix-class mailing list