first (naive) cut at identifier remapping and join injection
[dbsrgits/DBIx-Class.git] / t / dq / join.t
CommitLineData
9f9a7365 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use Test::Warn;
7use lib qw(t/lib);
8use DBICTest::Schema::Artist;
9use Data::Query::ExprDeclare;
10BEGIN {
11 DBICTest::Schema::Artist->has_many(
12 cds2 => 'DBICTest::Schema::CD',
13 expr { $_->foreign->artist == $_->self->artistid }
14 );
15 DBICTest::Schema::Artist->has_many(
16 cds2_pre2k => 'DBICTest::Schema::CD',
17 expr {
18 $_->foreign->artist == $_->self->artistid
19 & $_->foreign->year < 2000
20 }
21 );
22}
23use DBICTest;
24use DBIC::SqlMakerTest;
25
26my $schema = DBICTest->init_schema();
27
28my $mccrae = $schema->resultset('Artist')
29 ->find({ name => 'Caterwauler McCrae' });
30
31is($mccrae->cds2->count, 3, 'CDs returned from expr join');
32
33is($mccrae->cds2_pre2k->count, 2, 'CDs returned from expr w/cond');
34
44243306 35my $cds = $schema->resultset('CD')
36 ->search(expr { $_->artist->name eq 'Caterwauler McCrae' });
37
38is($cds->count, 3, 'CDs via join injection');
39
40my $tags = $schema->resultset('Tag')
41 ->search(expr { $_->cd->artist->name eq 'Caterwauler McCrae' });
42
43is($tags->count, 5, 'Tags via two step join injection');
44
9f9a7365 45done_testing;