Split DBIC from SQLMaker test (deprecated in next commit)
[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';
7
8use DBIx::Class::SQLMaker;
9my $sa = DBIx::Class::SQLMaker->new;
10
11my @j = (
12 { child => 'person' },
13 [ { father => 'person' }, { 'father.person_id' => 'child.father_id' }, ],
14 [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ],
15);
16my $match = 'person child JOIN person father ON ( father.person_id = '
17 . 'child.father_id ) JOIN person mother ON ( mother.person_id '
18 . '= child.mother_id )'
19 ;
20is_same_sql(
21 $sa->_recurse_from(@j),
22 $match,
23 'join 1 ok'
24);
25
26my @j2 = (
27 { mother => 'person' },
28 [ [ { child => 'person' },
29 [ { father => 'person' },
30 { 'father.person_id' => 'child.father_id' }
31 ]
32 ],
33 { 'mother.person_id' => 'child.mother_id' }
34 ],
35);
36$match = 'person mother JOIN (person child JOIN person father ON ('
37 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
38 . 'child.mother_id )'
39 ;
40is_same_sql(
41 $sa->_recurse_from(@j2),
42 $match,
43 'join 2 ok'
44);
45
46my @j3 = (
47 { child => 'person' },
48 [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ],
49 [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ],
50);
51$match = 'person child INNER JOIN person father ON ( father.person_id = '
52 . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id '
53 . '= child.mother_id )'
54 ;
55
56is_same_sql(
57 $sa->_recurse_from(@j3),
58 $match,
59 'join 3 (inner join) ok'
60);
61
62my @j4 = (
63 { mother => 'person' },
64 [ [ { child => 'person', -join_type => 'left' },
65 [ { father => 'person', -join_type => 'right' },
66 { 'father.person_id' => 'child.father_id' }
67 ]
68 ],
69 { 'mother.person_id' => 'child.mother_id' }
70 ],
71);
72$match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON ('
73 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
74 . 'child.mother_id )'
75 ;
76is_same_sql(
77 $sa->_recurse_from(@j4),
78 $match,
79 'join 4 (nested joins + join types) ok'
80);
81
82my @j5 = (
83 { child => 'person' },
84 [ { father => 'person' }, { 'father.person_id' => \'!= child.father_id' }, ],
85 [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ],
86);
87$match = 'person child JOIN person father ON ( father.person_id != '
88 . 'child.father_id ) JOIN person mother ON ( mother.person_id '
89 . '= child.mother_id )'
90 ;
91is_same_sql(
92 $sa->_recurse_from(@j5),
93 $match,
94 'join 5 (SCALAR reference for ON statement) ok'
95);
96
97done_testing;