8 use DBIC::SqlMakerTest;
13 my $schema = DBICTest->init_schema();
17 my $rs = $schema->resultset("Artist")
18 ->search_related('cds',
19 { 'tracks.position' => [1,2] },
20 { prefetch => [qw/tracks artist/] },
22 is ($rs->all, 5, 'Correct number of objects');
26 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
27 $schema->storage->debug(1);
30 is ($rs->count, 5, 'Correct count');
35 'SELECT COUNT( * ) FROM (SELECT cds.cdid FROM artist me JOIN cd cds ON cds.artist = me.artistid LEFT JOIN track tracks ON tracks.cd = cds.cdid JOIN artist artist ON artist.artistid = cds.artist WHERE tracks.position = ? OR tracks.position = ? GROUP BY cds.cdid) count_subq',
40 # collapsing prefetch with distinct
42 my $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
43 ->search_related('cds')->search_related('genre',
44 { 'genre.name' => 'foo' },
45 { prefetch => q(cds) },
47 is ($rs->all, 5, 'Correct number of objects');
51 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
52 $schema->storage->debug(1);
55 is ($rs->count, 5, 'Correct count');
60 'SELECT COUNT( * ) FROM (SELECT cds.cdid FROM artist me JOIN cd cds ON cds.artist = me.artistid LEFT JOIN track tracks ON tracks.cd = cds.cdid JOIN artist artist ON artist.artistid = cds.artist WHERE tracks.position = ? OR tracks.position = ? GROUP BY cds.cdid) count_subq',
65 # non-collapsing prefetch (no multi prefetches)
67 my $rs = $schema->resultset("CD")
68 ->search_related('tracks',
69 { position => [1,2] },
70 { prefetch => [qw/disc lyrics/] },
72 is ($rs->all, 10, 'Correct number of objects');
76 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
77 $schema->storage->debug(1);
80 is ($rs->count, 10, 'Correct count');
85 'SELECT COUNT( * ) FROM cd me JOIN track tracks ON tracks.cd = me.cdid JOIN cd disc ON disc.cdid = tracks.cd LEFT JOIN lyrics lyrics ON lyrics.track_id = tracks.trackid WHERE ( ( position = ? OR position = ? ) )',