[Dbix-class] @bind confusion
Peter Rabbitson
rabbit+dbic at rabbit.us
Tue Aug 3 09:59:59 GMT 2010
Wolfgang Kinkeldei wrote:
> Hello,
>
> when using subqueries in the 'from' part of a query, sometimes the list of @bind parameters is not maintained correct. As a simple testcase please find a primitive subselect enclosed that just does a count with a correlated subquery.
>
> <snip>
> # a simple counting subquery
> my $subquery =
> $schema->resultset('PersonRole')
> ->search( { role_id => 'admin' } ) # 1st bind param
> ->count_rs
> ->as_query;
>
> my @people =
> $schema->resultset('Person')
> ->search(
> {
> 'me.person_id' => 42, # 2nd bind param
> },
> {
> select => [ $subquery ],
> # whatever you join here, @bind gets confused
> join => 'person_regions'
> })
> ->all;
> <snap>
>
> if the 'join' attribute in the main query is left off, the SQL is fired as expected:
>
> SELECT (SELECT COUNT( * ) FROM person_role me WHERE ( role_id = $1 )) FROM person me WHERE ( me.person_id = $2 )
> DETAIL: parameters: $1 = 'admin', $2 = '42'
Ok then, do you understand that the above SQL does in fact? person_role and person
are *NOT CORRELATED* in any way. You might as well say:
SELECT 42 FROM person me WHERE (me.person_id = ?)
While dbic is incorrectly dropping the bind param (and I will look into this), your
query makes absolutely no sense as a whole. Remember - any subquery statement is
*ABSOLUTELY OBLIVIOUS* to anything outside of its outer closing ()s. I would like
to provide you with a correct search() call, but I literally can not understand what
you are trying to express with the above.
Cheers
More information about the DBIx-Class
mailing list