8 use DBIC::SqlMakerTest;
10 my $schema = DBICTest->init_schema();
11 my $orig_debug = $schema->storage->debug;
13 my $cdrs = $schema->resultset('CD')->search({ 'me.artist' => { '!=', 2 }});
17 siblings => $cdrs->search ({ artist => $_->get_column('artist') })->count - 1,
18 track_titles => [ map { $_->title } ($_->tracks->all) ],
23 $schema->storage->debugcb(sub { $queries++; });
24 $schema->storage->debug(1);
26 my $c_rs = $cdrs->search ({}, {
28 '+columns' => { sibling_count => $cdrs->search(
30 'siblings.artist' => { -ident => 'me.artist' },
31 'siblings.cdid' => { '!=' => ['-and', { -ident => 'me.cdid' }, 'bogus condition'] },
32 }, { alias => 'siblings' },
33 )->count_rs->as_query,
40 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
43 WHERE siblings.artist = me.artist
44 AND siblings.cdid != me.cdid
45 AND siblings.cdid != ?
48 tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at
50 LEFT JOIN track tracks
51 ON tracks.cd = me.cdid
56 [ 'siblings.cdid' => 'bogus condition' ],
60 'Expected SQL on correlated realiased subquery'
66 track_titles => [ map { $_->title } ($_->tracks->all) ],
67 siblings => $_->get_column ('sibling_count'),
72 'Proper information retrieved from correlated subquery'
75 is ($queries, 1, 'Only 1 query fired to retrieve everything');
77 $schema->storage->debug($orig_debug);
78 $schema->storage->debugcb(undef);