X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frun%2F16joins.tl;h=cab0a9319e5eabce34759a0b1f3cb0f03423e339;hb=8452e496;hp=3f7e596b950320d915db94a9d97763d9b9c424dc;hpb=dd417d064c7b003f1a6ba924045c79045ce0b515;p=dbsrgits%2FDBIx-Class.git diff --git a/t/run/16joins.tl b/t/run/16joins.tl index 3f7e596..cab0a93 100644 --- a/t/run/16joins.tl +++ b/t/run/16joins.tl @@ -6,7 +6,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 22 ); + : ( tests => 23 ); } # test the abstract join => SQL generator @@ -51,7 +51,7 @@ $match = 'person child INNER JOIN person father ON ( father.person_id = ' is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok'); -my $rs = DBICTest::CD->search( +my $rs = DBICTest->class("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { from => [ { 'me' => 'cd' }, [ @@ -64,7 +64,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Forkful of bees', 'Correct record returned'); -$rs = DBICTest::CD->search( +$rs = DBICTest->class("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); @@ -72,7 +72,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Forkful of bees', 'Correct record returned'); -$rs = DBICTest::CD->search( +$rs = DBICTest->class("CD")->search( { 'artist.name' => 'We Are Goth', 'liner_notes.notes' => 'Kill Yourself!' }, { join => [ qw/artist liner_notes/ ] }); @@ -81,7 +81,14 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Come Be Depressed With Us', 'Correct record returned'); -$rs = DBICTest::Artist->search( +# when using join attribute, make sure slice()ing all objects has same count as all() +$rs = DBICTest->class("CD")->search( + { 'artist' => 1 }, + { join => [qw/artist/], order_by => 'artist.name' } +); +cmp_ok( scalar $rs->all, '==', scalar $rs->slice(0, $rs->count - 1), 'slice() with join has same count as all()' ); + +$rs = DBICTest->class("Artist")->search( { 'liner_notes.notes' => 'Kill Yourself!' }, { join => { 'cds' => 'liner_notes' } }); @@ -89,18 +96,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->name, 'We Are Goth', 'Correct record returned'); -DBICTest::Schema::CD->add_relationship( - artist => 'DBICTest::Schema::Artist', - { 'foreign.artistid' => 'self.artist' }, - { accessor => 'filter' }, -); - -DBICTest::Schema::CD->add_relationship( - liner_notes => 'DBICTest::Schema::LinerNotes', - { 'foreign.liner_id' => 'self.cdid' }, - { join_type => 'LEFT', accessor => 'single' }); - -$rs = DBICTest::CD->search( +$rs = DBICTest->class("CD")->search( { 'artist.name' => 'Caterwauler McCrae' }, { prefetch => [ qw/artist liner_notes/ ], order_by => 'me.cdid' }); @@ -115,7 +111,7 @@ my @cd = $rs->all; is($cd[0]->title, 'Spoonful of bees', 'First record returned ok'); -ok(!exists $cd[0]->{_relationship_data}{liner_notes}, 'No prefetch for NULL LEFT JOIN'); +ok(!defined $cd[0]->liner_notes, 'No prefetch for NULL LEFT join'); is($cd[1]->{_relationship_data}{liner_notes}->notes, 'Buy Whiskey!', 'Prefetch for present LEFT JOIN'); @@ -135,19 +131,19 @@ $trace->close; unlink 't/var/dbic.trace'; is($selects, 1, 'prefetch ran only 1 select statement'); -my ($artist) = DBICTest::Artist->search({ 'cds.year' => 2001 }, +my ($artist) = DBICTest->class("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!' }, +my @cds = DBICTest->class("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' }, +my @artists = DBICTest->class("Artist")->search({ 'tags.tag' => 'Shiny' }, { join => { 'cds' => 'tags' } }); cmp_ok( @artists, '==', 2, "two-join search ok" );