Commit | Line | Data |
73856587 |
1 | use strict; |
2 | use Test::More; |
3 | |
4 | BEGIN { |
5 | eval "use DBD::SQLite"; |
6 | plan $@ |
7 | ? ( skip_all => 'needs DBD::SQLite for testing' ) |
8 | : ( tests => 4 ); |
9 | } |
10 | |
11 | use lib qw(t/lib); |
12 | |
13 | use_ok('DBICTest'); |
14 | |
15 | # test the abstract join => SQL generator |
16 | my $sa = new DBIC::SQL::Abstract; |
17 | |
18 | my @j = ( |
19 | { child => 'person' }, |
20 | [ { father => 'person' }, { 'father.person_id' => 'child.father_id' }, ], |
21 | [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ], |
22 | ); |
23 | my $match = 'person AS child JOIN (person AS father) ON ( father.person_id = ' |
24 | . 'child.father_id ) JOIN (person AS mother) ON ( mother.person_id ' |
25 | . '= child.mother_id )' |
26 | ; |
27 | is( $sa->_recurse_from(@j), $match, 'join 1 ok' ); |
28 | |
29 | my @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 AS mother JOIN (person AS child JOIN (person AS father) ON (' |
40 | . ' father.person_id = child.father_id )) ON ( mother.person_id = ' |
41 | . 'child.mother_id )' |
42 | ; |
43 | is( $sa->_recurse_from(@j2), $match, 'join 2 ok' ); |
44 | |
45 | my @j3 = ( |
46 | { child => 'person' }, |
47 | [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ], |
48 | [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ], |
49 | ); |
50 | my $match = 'person AS child INNER JOIN (person AS father) ON ( father.person_id = ' |
51 | . 'child.father_id ) INNER JOIN (person AS mother) ON ( mother.person_id ' |
52 | . '= child.mother_id )' |
53 | ; |
54 | |
55 | is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok'); |