fix for key => [] + tests + cleanup of 02where.t
[dbsrgits/SQL-Abstract.git] / t / 04from.t
CommitLineData
41751122 1#!/usr/bin/perl
83cab70b 2
3use strict;
41751122 4use warnings;
5use Test::More;
83cab70b 6
41751122 7
8plan tests => 4;
83cab70b 9
10use SQL::Abstract;
11
83cab70b 12my $sa = new SQL::Abstract;
13
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( $sa->_recurse_from(@j), $match, 'join 1 ok' );
24
25my @j2 = (
26 { mother => 'person' },
27 [ [ { child => 'person' },
28 [ { father => 'person' },
29 { 'father.person_id' => 'child.father_id' }
30 ]
31 ],
32 { 'mother.person_id' => 'child.mother_id' }
33 ],
34);
35$match = 'person mother JOIN (person child JOIN person father ON ('
36 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
37 . 'child.mother_id )'
38 ;
39is( $sa->_recurse_from(@j2), $match, 'join 2 ok' );
40
41my @j3 = (
42 { child => 'person' },
43 [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ],
44 [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ],
45);
46$match = 'person child INNER JOIN person father ON ( father.person_id = '
47 . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id '
48 . '= child.mother_id )'
49 ;
50
51is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok');
52
53my @j4 = (
54 { mother => 'person' },
55 [ [ { child => 'person', -join_type => 'left' },
56 [ { father => 'person', -join_type => 'right' },
57 { 'father.person_id' => 'child.father_id' }
58 ]
59 ],
60 { 'mother.person_id' => 'child.mother_id' }
61 ],
62);
63$match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON ('
64 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
65 . 'child.mother_id )'
66 ;
67is( $sa->_recurse_from(@j4), $match, 'join 4 (nested joins + join types) ok');