[Dbix-class] modifying join condition in search

Pedro Melo melo at simplicidade.org
Thu Jul 19 18:01:38 GMT 2007


Hi,

On Jul 19, 2007, at 11:55 AM, Jon Schutz wrote:

>
>> 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
>>
>
> First case produces a result row for every row in ph_topics.
>
> Second case produces a result row only where watchers.user_id = 5.
>
> One wonders though if the original poster wouldn't prefer the second
> case.

No I want the first case. The watchers table has a row for each user/ 
topic that is being watched.

I want to know, for all topics in my query which ones are being watched.


> In answer to the original question, I believe the parameter '5'  
> could be
> passed through as a bind variable; see
>
> http://search.cpan.org/~mstrout/DBIx-
> Class-0.08003/lib/DBIx/Class/Manual/ 
> Cookbook.pod#Arbitrary_SQL_through_a_custom_ResultSource

hmms.. I'll have to experiment.

Thanks for the tip.

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