sub run_tests {
+my $schema = shift;
use IO::File;
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 22 );
+ : ( tests => 23 );
}
# test the abstract join => SQL generator
is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok');
-my $rs = DBICTest::CD->search(
+my $rs = $schema->resultset("CD")->search(
{ 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
{ from => [ { 'me' => 'cd' },
[
is($rs->first->title, 'Forkful of bees', 'Correct record returned');
-$rs = DBICTest::CD->search(
+$rs = $schema->resultset("CD")->search(
{ 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
{ join => 'artist' });
is($rs->first->title, 'Forkful of bees', 'Correct record returned');
-$rs = DBICTest::CD->search(
+$rs = $schema->resultset("CD")->search(
{ 'artist.name' => 'We Are Goth',
'liner_notes.notes' => 'Kill Yourself!' },
{ join => [ qw/artist liner_notes/ ] });
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 = $schema->resultset("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 = $schema->resultset("Artist")->search(
{ 'liner_notes.notes' => 'Kill Yourself!' },
{ join => { 'cds' => 'liner_notes' } });
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 = $schema->resultset("CD")->search(
{ 'artist.name' => 'Caterwauler McCrae' },
{ prefetch => [ qw/artist liner_notes/ ],
order_by => 'me.cdid' });
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');
unlink 't/var/dbic.trace';
is($selects, 1, 'prefetch ran only 1 select statement');
-my ($artist) = DBICTest::Artist->search({ 'cds.year' => 2001 },
+my ($artist) = $schema->resultset("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 = $schema->resultset("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 = $schema->resultset("Artist")->search({ 'tags.tag' => 'Shiny' },
{ join => { 'cds' => 'tags' } });
cmp_ok( @artists, '==', 2, "two-join search ok" );