Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
8a3fa4ae |
3 | use warnings; |
4a233f30 |
4 | use strict; |
8a3fa4ae |
5 | |
6 | use Test::More; |
c0329273 |
7 | |
a5a7bb73 |
8 | use DBICTest ':DiffSQL'; |
8a3fa4ae |
9 | |
10 | my $schema = DBICTest->init_schema(); |
11 | |
12 | |
13 | # a regular belongs_to prefetch |
14 | my $cds = $schema->resultset('CD')->search ({}, { prefetch => 'artist' } ); |
15 | |
16 | my $nulls = { |
17 | hashref => {}, |
18 | arrayref => [], |
19 | undef => undef, |
20 | }; |
21 | |
22 | # make sure null-prefetches do not screw with the final sql: |
23 | for my $type (keys %$nulls) { |
41a5d675 |
24 | is_same_sql_bind ( |
25 | $cds->search({}, { prefetch => { artist => $nulls->{$type} } })->as_query, |
26 | '( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, |
27 | artist.artistid, artist.name, artist.rank, artist.charfield |
28 | FROM cd me |
29 | JOIN artist artist |
30 | ON artist.artistid = me.artist |
31 | )', [], |
32 | "same sql with null $type prefetch" |
33 | ); |
8a3fa4ae |
34 | } |
35 | |
36 | # make sure left join is carried only starting from the first has_many |
37 | is_same_sql_bind ( |
38 | $cds->search({}, { prefetch => { artist => { cds => 'artist' } } })->as_query, |
39 | '( |
40 | SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, |
41 | artist.artistid, artist.name, artist.rank, artist.charfield, |
42 | cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track, |
43 | artist_2.artistid, artist_2.name, artist_2.rank, artist_2.charfield |
44 | FROM cd me |
45 | JOIN artist artist ON artist.artistid = me.artist |
46 | LEFT JOIN cd cds ON cds.artist = artist.artistid |
47 | LEFT JOIN artist artist_2 ON artist_2.artistid = cds.artist |
8a3fa4ae |
48 | )', |
49 | [], |
50 | ); |
51 | |
52 | done_testing; |