my $schema = DBICTest->init_schema();
+my $orig_debug = $schema->storage->debug;
+
use IO::File;
BEGIN {
my $queries = 0;
$schema->storage->debugcb(sub { $queries++ });
-
-$queries = 0;
$schema->storage->debug(1);
my @cd = $rs->all;
is($queries, 1, 'prefetch ran only 1 select statement');
-$schema->storage->debug(0);
+$schema->storage->debug($orig_debug);
+$schema->storage->debugobj->callback(undef);
# test for partial prefetch via columns attr
my $cd = $schema->resultset('CD')->find(1,
# start test for nested prefetch SELECT count
$queries = 0;
+$schema->storage->debugcb(sub { $queries++ });
$schema->storage->debug(1);
$rs = $schema->resultset('Tag')->search(
is($queries, 1, 'find with prefetch ran exactly 1 select statement (excluding column_info)');
-$schema->storage->debug(0);
+$schema->storage->debug($orig_debug);
+$schema->storage->debugobj->callback(undef);
$rs = $schema->resultset('Tag')->search(
{},
is($rs->next->name, 'Caterwauler McCrae', "Correct artist returned");
$queries = 0;
+$schema->storage->debugcb(sub { $queries++ });
$schema->storage->debug(1);
my $tree_like =
$tree_like = $tree_like->parent;
is($tree_like->name, 'foo', 'Third level up ok');
-$schema->storage->debug(0);
+$schema->storage->debug($orig_debug);
+$schema->storage->debugobj->callback(undef);
cmp_ok($queries, '==', 1, 'Only one query run');
$tree_like = $tree_like->search_related('children')->search_related('children')->search_related('children')->first;
is($tree_like->name, 'quux', 'Tree search_related ok');
-$tree_like = $schema->resultset('TreeLike')->search({ 'children.id' => 2 });
-$tree_like = $tree_like->search_related('children', undef, { prefetch => { children => 'children' } })->first;
-is($tree_like->children->first->children->first->name, 'quux', 'Tree search_related with prefetch ok');
+$tree_like = $schema->resultset('TreeLike')->search_related('children',
+ { 'children.id' => 2, 'children_2.id' => 3 },
+ { prefetch => { children => 'children' } }
+ )->first;
+is(eval { $tree_like->children->first->children->first->name }, 'quux',
+ 'Tree search_related with prefetch ok');
-$tree_like = $schema->resultset('TreeLike')->search(
+$tree_like = eval { $schema->resultset('TreeLike')->search(
{ 'children.id' => 2, 'children_2.id' => 5 },
- { join => [qw/children children/] })->first;
-is($tree_like->name, 'foo', 'Tree with multiple has_many joins ok');
+ { join => [qw/children children/] }
+ )->search_related('children', { 'children_4.id' => 6 }, { prefetch => 'children' }
+ )->first->children->first; };
+is(eval { $tree_like->name }, 'fong', 'Tree with multiple has_many joins ok');
# test that collapsed joins don't get a _2 appended to the alias
})->search_related('tracks')->first;
};
-like( $sql, qr/^SELECT tracks.trackid/, "collapsed join didn't add _2 to alias" );
+like( $sql, qr/^SELECT tracks_2\.trackid/, "join not collapsed for search_related" );
-$schema->storage->debug(0);
+$schema->storage->debug($orig_debug);
+$schema->storage->debugobj->callback(undef);