I think we are done here
[dbsrgits/DBIx-Class.git] / t / prefetch / join_type.t
CommitLineData
8a3fa4ae 1use warnings;
2
3use Test::More;
8a3fa4ae 4use lib qw(t/lib);
5use DBIC::SqlMakerTest;
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
10
11# a regular belongs_to prefetch
12my $cds = $schema->resultset('CD')->search ({}, { prefetch => 'artist' } );
13
14my $nulls = {
15 hashref => {},
16 arrayref => [],
17 undef => undef,
18};
19
20# make sure null-prefetches do not screw with the final sql:
21for my $type (keys %$nulls) {
22# is_same_sql_bind (
23# $cds->search({}, { prefetch => { artist => $nulls->{$type} } })->as_query,
24# $cds->as_query,
25# "same sql with null $type prefetch"
26# );
27}
28
29# make sure left join is carried only starting from the first has_many
30is_same_sql_bind (
31 $cds->search({}, { prefetch => { artist => { cds => 'artist' } } })->as_query,
32 '(
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
37 FROM cd me
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
4e9fc3f3 41 ORDER BY me.cdid
8a3fa4ae 42 )',
43 [],
44);
45
46done_testing;