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