From: Matt S Trout Date: Fri, 9 Sep 2005 08:12:20 +0000 (+0000) Subject: HasMany now does a LEFT JOIN, added more tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f85f550e1a6edce9b939b32b604bbe85f1650d39;p=dbsrgits%2FDBIx-Class-Historic.git HasMany now does a LEFT JOIN, added more tests --- diff --git a/lib/DBIx/Class/CDBICompat/HasMany.pm b/lib/DBIx/Class/CDBICompat/HasMany.pm index 7b779e3..56c044d 100644 --- a/lib/DBIx/Class/CDBICompat/HasMany.pm +++ b/lib/DBIx/Class/CDBICompat/HasMany.pm @@ -44,6 +44,7 @@ sub has_many { $class->add_relationship($rel, $f_class, { "foreign.${f_key}" => "self.${self_key}" }, { accessor => 'multi', + join_type => 'LEFT', ($cascade ? ('cascade_delete' => 1) : ()), %$args } ); return 1; diff --git a/t/16joins.t b/t/16joins.t index a334110..a810024 100644 --- a/t/16joins.t +++ b/t/16joins.t @@ -5,7 +5,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 17 ); + : ( tests => 21 ); } use lib qw(t/lib); @@ -47,7 +47,7 @@ my @j3 = ( [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ], [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ], ); -my $match = 'person child INNER JOIN person father ON ( father.person_id = ' +$match = 'person child INNER JOIN person father ON ( father.person_id = ' . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id ' . '= child.mother_id )' ; @@ -120,3 +120,20 @@ ok(!exists $cd[0]->{_relationship_data}{liner_notes}, 'No prefetch for NULL LEFT is($cd[1]->{_relationship_data}{liner_notes}->notes, 'Buy Whiskey!', 'Prefetch for present LEFT JOIN'); is($cd[2]->{_inflated_column}{artist}->name, 'Caterwauler McCrae', 'Prefetch on parent object ok'); + +my ($artist) = DBICTest::Artist->search({ 'cds.year' => 2001 }, + { order_by => 'artistid DESC', join => 'cds' }); + +is($artist->name, 'Random Boy Band', "Join search by object ok"); + +my @cds = DBICTest::CD->search({ 'liner_notes.notes' => 'Buy Merch!' }, + { join => 'liner_notes' }); + +cmp_ok(scalar @cds, '==', 1, "Single CD retrieved via might_have"); + +is($cds[0]->title, "Generic Manufactured Singles", "Correct CD retrieved"); + +my @artists = DBICTest::Artist->search({ 'tags.tag' => 'Shiny' }, + { join => { 'cds' => 'tags' } }); + +cmp_ok( @artists, '==', 2, "two-join search ok" );