Add strict/warnings test, adjust all offenders (wow, that was a lot)
[dbsrgits/DBIx-Class.git] / t / prefetch / join_type.t
CommitLineData
8a3fa4ae 1use warnings;
4a233f30 2use strict;
8a3fa4ae 3
4use Test::More;
8a3fa4ae 5use lib qw(t/lib);
6use DBIC::SqlMakerTest;
7use DBICTest;
8
9my $schema = DBICTest->init_schema();
10
11
12# a regular belongs_to prefetch
13my $cds = $schema->resultset('CD')->search ({}, { prefetch => 'artist' } );
14
15my $nulls = {
16 hashref => {},
17 arrayref => [],
18 undef => undef,
19};
20
21# make sure null-prefetches do not screw with the final sql:
22for my $type (keys %$nulls) {
23# is_same_sql_bind (
24# $cds->search({}, { prefetch => { artist => $nulls->{$type} } })->as_query,
25# $cds->as_query,
26# "same sql with null $type prefetch"
27# );
28}
29
30# make sure left join is carried only starting from the first has_many
31is_same_sql_bind (
32 $cds->search({}, { prefetch => { artist => { cds => 'artist' } } })->as_query,
33 '(
34 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
35 artist.artistid, artist.name, artist.rank, artist.charfield,
36 cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track,
37 artist_2.artistid, artist_2.name, artist_2.rank, artist_2.charfield
38 FROM cd me
39 JOIN artist artist ON artist.artistid = me.artist
40 LEFT JOIN cd cds ON cds.artist = artist.artistid
41 LEFT JOIN artist artist_2 ON artist_2.artistid = cds.artist
c9733800 42 ORDER BY cds.artist, cds.year ASC
8a3fa4ae 43 )',
44 [],
45);
46
47done_testing;