From: Brandon L. Black Date: Thu, 8 Jun 2006 03:28:24 +0000 (+0000) Subject: bugfix for join-types in nested joins using the from attribute (+ test) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca7b9fdf18b093c46189fc5ba00491d1c02f813f;p=dbsrgits%2FDBIx-Class-Historic.git bugfix for join-types in nested joins using the from attribute (+ test) --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 3eafc75..605f8bb 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -133,8 +133,9 @@ sub _recurse_from { # check whether a join type exists my $join_clause = ''; - if (ref($to) eq 'HASH' and exists($to->{-join_type})) { - $join_clause = ' '.uc($to->{-join_type}).' JOIN '; + my $to_jt = ref($to) eq 'ARRAY' ? $to->[0] : $to; + if (ref($to_jt) eq 'HASH' and exists($to_jt->{-join_type})) { + $join_clause = ' '.uc($to_jt->{-join_type}).' JOIN '; } else { $join_clause = ' JOIN '; } diff --git a/t/76joins.t b/t/76joins.t index c697254..0fc9f53 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -13,7 +13,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 42 ); + : ( tests => 43 ); } # figure out if we've got a version of sqlite that is older than 3.2.6, in @@ -70,6 +70,22 @@ $match = 'person child INNER JOIN person father ON ( father.person_id = ' is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok'); +my @j4 = ( + { mother => 'person' }, + [ [ { child => 'person', -join_type => 'left' }, + [ { father => 'person', -join_type => 'right' }, + { 'father.person_id' => 'child.father_id' } + ] + ], + { 'mother.person_id' => 'child.mother_id' } + ], +); +$match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON (' + . ' father.person_id = child.father_id )) ON ( mother.person_id = ' + . 'child.mother_id )' + ; +is( $sa->_recurse_from(@j4), $match, 'join 4 (nested joins + join types) ok'); + my $rs = $schema->resultset("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { from => [ { 'me' => 'cd' },