LEFT JOIN + rework join tests
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 200_join.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 4;
5 use Test::Differences;
6
7 use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
8
9 my $sqla = SQL::Abstract->create(1);
10
11 is $sqla->dispatch(
12   { -type => 'join',
13     args => [
14       {-type => name => args => [qw/bar/]},
15       {-type => name => args => [qw/foo/]},
16     ],
17     on => { 
18       -type => 'expr',
19       op => '==',
20       args => [
21         { -type => 'name', args => [qw/foo id/] },
22         { -type => 'name', args => [qw/me foo_id/] },
23       ]
24     }
25   }
26 ), "bar JOIN foo ON (foo.id = me.foo_id)", 
27    "simple join clause";
28
29 is $sqla->dispatch(
30   { -type => 'join',
31     args => [
32       {-type => name => args => [qw/fnord/]},
33       {-type => 'alias', ident => {-type => name => args => [qw/foo/]}, as => 'bar' }
34     ],
35     using => { -type => 'name', args => [qw/foo_id/] },
36   }
37 ), "fnord JOIN foo AS bar USING (foo_id)", 
38    "using join clause";
39
40
41 is $sqla->dispatch(
42   { -type => 'join',
43     join_type => 'LEFT',
44     args => [
45       {-type => name => args => [qw/fnord/]},
46       {-type => 'alias', ident => {-type => name => args => [qw/foo/]}, as => 'bar' }
47     ],
48     using => { -type => 'name', args => [qw/foo_id/] },
49   }
50 ), "fnord LEFT JOIN foo AS bar USING (foo_id)", 
51    "using left join clause";