Slight wording change to new_related() POD.
[dbsrgits/DBIx-Class.git] / t / 90join_torture.t
CommitLineData
ae515736 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
08a39415 10plan tests => 8;
00a80124 11
12my @rs1a_results = $schema->resultset("Artist")->search_related('cds', {title => 'Forkful of bees'}, {order_by => 'title'});
13is($rs1a_results[0]->title, 'Forkful of bees', "bare field conditions okay after search related");
ae515736 14
15my $rs1 = $schema->resultset("Artist")->search({ 'tags.tag' => 'Blue' }, { join => {'cds' => 'tracks'}, prefetch => {'cds' => 'tags'} });
16my @artists = $rs1->all;
17cmp_ok(@artists, '==', 1, "Two artists returned");
18
19my $rs2 = $rs1->search({ artistid => '1' }, { join => {'cds' => {'cd_to_producer' => 'producer'} } });
b253a82b 20
21my @artists2 = $rs2->search({ 'producer.name' => 'Matt S Trout' });
22my @cds = $artists2[0]->cds;
23cmp_ok(scalar @cds, '==', 1, "condition based on inherited join okay");
24
00a80124 25# this is wrong, should accept me.title really
26my $rs3 = $rs2->search_related('cds')->search({'cds.title' => 'Forkful of bees'});
27
08a39415 28cmp_ok($rs3->count, '==', 1, "Three artists returned");
ae515736 29
30my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, { join => ['tracks', 'artist'], prefetch => 'artist' });
31my @rs4_results = $rs4->all;
32
33
34is($rs4_results[0]->cdid, 1, "correct artist returned");
35
36my $rs5 = $rs4->search({'tracks.title' => 'Sticky Honey'});
37is($rs5->count, 1, "search without using previous joins okay");
38
08a39415 39my $record_rs = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search(undef, { prefetch => { 'cds' => 'tracks' }});
40my $record_jp = $record_rs->next;
41ok($record_jp, "prefetch on same rel okay");
42
43my $cd = $schema->resultset("CD")->find(1);
44my $producers = $cd->producers;
45is($producers->find(2)->name, 'Bob The Builder', "find on many to many okay");
46
ae515736 471;