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 # Added test by mo per http://scsys.co.uk:8001/31870
42 todo_skip "This breaks stuff", 3;
43 my $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
44 ->search_related('cds')->search_related('genre',
45 { 'genre.name' => 'foo' },
46 { prefetch => q(cds) },
48 is ($rs->all, 5, 'Correct number of objects');
52 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
53 $schema->storage->debug(1);
56 is ($rs->count, 5, 'Correct count');
61 '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',
66 # collapsing prefetch with distinct
68 todo_skip "This is busted", 3;
69 my $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
70 ->search_related('cds')->search_related('genre',
71 { 'genre.name' => 'foo' },
72 { prefetch => q(cds) },
74 is ($rs->all, 5, 'Correct number of objects');
78 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
79 $schema->storage->debug(1);
82 is ($rs->count, 5, 'Correct count');
87 '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',
92 # non-collapsing prefetch (no multi prefetches)
94 my $rs = $schema->resultset("CD")
95 ->search_related('tracks',
96 { position => [1,2] },
97 { prefetch => [qw/disc lyrics/] },
99 is ($rs->all, 10, 'Correct number of objects');
103 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
104 $schema->storage->debug(1);
107 is ($rs->count, 10, 'Correct count');
112 '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 = ? ) )',
117 # Added test by mo per http://scsys.co.uk:8001/31873
119 todo_skip "This breaks stuff", 5;
120 my $rs = $schema->resultset("Artwork")->search(undef, {distinct => 1})
121 ->search_related('artwork_to_artist')->search_related('artist',
123 { prefetch => q(cds) },
125 is($rs->all, 0, 'failure without WHERE');
127 $rs = $schema->resultset("Artwork")->search(undef, {distinct => 1})
128 ->search_related('artwork_to_artist')->search_related('artist',
129 { 'cds.title' => 'foo' }, # this line has changed
130 { prefetch => q(cds) },
132 is($rs->all, 0, 'success with WHERE');
136 $rs = $schema->resultset("Artist")->search(undef)#, {distinct => 1})
137 ->search_related('cds')->search_related('genre',
138 { 'genre.name' => 'foo' },
139 { prefetch => q(cds) },
141 is($rs->all, 0, 'success without distinct');
143 $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
144 ->search_related('cds')->search_related('genre',
145 { 'genre.name' => 'foo' },
146 #{ prefetch => q(cds) },
148 is($rs->all, 0, 'success without prefetch');
150 $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
151 ->search_related('cds')->search_related('genre',
152 { 'genre.name' => 'foo' },
153 { prefetch => q(cds) },
155 is($rs->all, 0, 'failure with distinct');