Take a copy instead of weakening in 5.8 leak workaround
[dbsrgits/DBIx-Class.git] / t / sqlmaker / legacy_joins.t
CommitLineData
638cd950 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest ':DiffSQL';
1efc866d 7use DBIx::Class::_Util 'sigwarn_silencer';
638cd950 8
9use DBIx::Class::SQLMaker;
10my $sa = DBIx::Class::SQLMaker->new;
11
1efc866d 12$SIG{__WARN__} = sigwarn_silencer( qr/\Q{from} structures with conditions not conforming to the SQL::Abstract syntax are deprecated/ );
13
638cd950 14my @j = (
15 { child => 'person' },
16 [ { father => 'person' }, { 'father.person_id' => 'child.father_id' }, ],
17 [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ],
18);
19my $match = 'person child JOIN person father ON ( father.person_id = '
20 . 'child.father_id ) JOIN person mother ON ( mother.person_id '
21 . '= child.mother_id )'
22 ;
23is_same_sql(
24 $sa->_recurse_from(@j),
25 $match,
26 'join 1 ok'
27);
28
29my @j2 = (
30 { mother => 'person' },
31 [ [ { child => 'person' },
32 [ { father => 'person' },
33 { 'father.person_id' => 'child.father_id' }
34 ]
35 ],
36 { 'mother.person_id' => 'child.mother_id' }
37 ],
38);
39$match = 'person mother JOIN (person child JOIN person father ON ('
40 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
41 . 'child.mother_id )'
42 ;
43is_same_sql(
44 $sa->_recurse_from(@j2),
45 $match,
46 'join 2 ok'
47);
48
49my @j3 = (
50 { child => 'person' },
51 [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ],
52 [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ],
53);
54$match = 'person child INNER JOIN person father ON ( father.person_id = '
55 . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id '
56 . '= child.mother_id )'
57 ;
58
59is_same_sql(
60 $sa->_recurse_from(@j3),
61 $match,
62 'join 3 (inner join) ok'
63);
64
65my @j4 = (
66 { mother => 'person' },
67 [ [ { child => 'person', -join_type => 'left' },
68 [ { father => 'person', -join_type => 'right' },
69 { 'father.person_id' => 'child.father_id' }
70 ]
71 ],
72 { 'mother.person_id' => 'child.mother_id' }
73 ],
74);
75$match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON ('
76 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
77 . 'child.mother_id )'
78 ;
79is_same_sql(
80 $sa->_recurse_from(@j4),
81 $match,
82 'join 4 (nested joins + join types) ok'
83);
84
85my @j5 = (
86 { child => 'person' },
87 [ { father => 'person' }, { 'father.person_id' => \'!= child.father_id' }, ],
88 [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ],
89);
90$match = 'person child JOIN person father ON ( father.person_id != '
91 . 'child.father_id ) JOIN person mother ON ( mother.person_id '
92 . '= child.mother_id )'
93 ;
94is_same_sql(
95 $sa->_recurse_from(@j5),
96 $match,
97 'join 5 (SCALAR reference for ON statement) ok'
98);
99
100done_testing;