5 use DBIC::SqlMakerTest;
8 my $schema = DBICTest->init_schema();
11 # a regular belongs_to prefetch
12 my $cds = $schema->resultset('CD')->search ({}, { prefetch => 'artist' } );
20 # make sure null-prefetches do not screw with the final sql:
21 for my $type (keys %$nulls) {
23 # $cds->search({}, { prefetch => { artist => $nulls->{$type} } })->as_query,
25 # "same sql with null $type prefetch"
29 # make sure left join is carried only starting from the first has_many
31 $cds->search({}, { prefetch => { artist => { cds => 'artist' } } })->as_query,
33 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
34 artist.artistid, artist.name, artist.rank, artist.charfield,
35 cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track,
36 artist_2.artistid, artist_2.name, artist_2.rank, artist_2.charfield
38 JOIN artist artist ON artist.artistid = me.artist
39 LEFT JOIN cd cds ON cds.artist = artist.artistid
40 LEFT JOIN artist artist_2 ON artist_2.artistid = cds.artist
41 ORDER BY cds.artist, cds.year ASC