[Dbix-class] Second join gets eaten in _merge_attr

brett gardner brett at clientcomm.com.au
Tue Oct 30 21:25:46 GMT 2007


I have a flag that I set to turn on the behaviour. Also I only do it for 
one particular resultset type and for only one of the relationships in 
that resultset.

Zbigniew Lukasiak wrote:
> On 10/29/07, brett gardner <brett at clientcomm.com.au> wrote:
>   
>> I don't think its as simple as that.
>>
>> I recently had to implement this behaviour and realised that in some
>> cases you might need to rename the columns in the query. eg
>>
>> $rs->search({'foo.bar_id' => 2},{join=>'foo'});
>>
>> then later
>>
>> my $new_rs = $rs->search({'foo.bar_id' = 45},{join=>'foo'});
>>
>> which would result in the query
>>
>> SELECT ....
>> FROM tbl1 LEFT JOIN foo ON (...)
>> LEFT JOIN foo foo2 ON (...)
>> WHERE
>> foo.bar_id = 2 AND foo.bar_id = 45
>>
>> Which is incorrect. as the second search clause should be "foo2.bar_id =
>> 45".
>>
>> Because the code may not be aware of how many times "foo" has been
>> joined already the resultset needs to rename the search fields in the
>> search method.
>>     
>
> So you have two cases -
>
> 1. The one that is covered by the current code is when you need to
> search by a field in a table that is already joined
>
> 2. The case that you have where you need to really join the table second time
>
> When you use second time the same field it obviously can be only the
> case 2 - but in general I cannot see any way to discriminate between
> those two cases.
>
> I have something like the case 2 - because I need to join a table
> multiple times. With the patch from luke I can do this at least
> manually, but it would be nice the renaming of parameters was done
> automatically.
>
>   



More information about the DBIx-Class mailing list