[Dbix-class] JOIN question
mike
pulsation at gmail.com
Wed Dec 13 21:02:53 GMT 2006
On 11/26/06, Bernhard Graf <dbic2 at augensalat.de> wrote:
> Hi,
>
> I'm unable to define a certain join condition with DBIC.
> Maybe someone can have a look and help me out, perhaps also Matt,
> because it seems there is a small bug with the "from"-attribute
> (see at the end).
i created and submitted a patch for this (with tests), but it was
never applied. probably because i didn't stay on mst's ass about it.
the patch follows. it merely extends the scalar ref ability of
conditions in the where clause to the join clause.
-mike
--- SNIP --- SNIP --- SNIP ---
Index: t/76joins.t
===================================================================
--- t/76joins.t (revision 2797)
+++ t/76joins.t (working copy)
@@ -16,7 +16,7 @@
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 49 );
+ : ( tests => 50 );
}
# figure out if we've got a version of sqlite that is older than 3.2.6, in
@@ -89,6 +89,20 @@
;
is( $sa->_recurse_from(@j4), $match, 'join 4 (nested joins + join types) ok');
+my $old_quote_char = $sa->{quote_char};
+$sa->{quote_char} = '`';
+my @j5 = (
+ { mother => 'person' },
+ [ { child => 'person', -join_type => 'left' },
+ { 'father.person_id' => 'child.father_id', 'father.name' =>
\'IS NOT NULL' }
+ ]
+);
+$match = '`person` `mother` LEFT JOIN `person` `child` ON ( `father.name` = '
+ . 'IS NOT NULL AND `father.person_id` = `child.father_id` )'
+ ;
+is ($sa->_recurse_from(@j5), $match, 'join 5 (literal join condition
with quoted identifiers) ok');
+$sa->{quote_char} = $old_quote_char;
+
my $rs = $schema->resultset("CD")->search(
{ 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
{ from => [ { 'me' => 'cd' },
Index: lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- lib/DBIx/Class/Storage/DBI.pm (revision 2797)
+++ lib/DBIx/Class/Storage/DBI.pm (working copy)
@@ -232,7 +232,7 @@
if (ref $cond eq 'HASH') {
my %j;
for (keys %$cond) {
- my $x = '= '.$self->_quote($cond->{$_}); $j{$_} = \$x;
+ my $x = '= '.(ref($cond->{$_}) ? ${ $cond->{$_} } :
$self->_quote($cond->{$_})); $j{$_} = \$x;
};
return $self->_recurse_where(\%j);
} elsif (ref $cond eq 'ARRAY') {
--- SNIP --- SNIP --- SNIP ---
More information about the Dbix-class
mailing list