nested has_many prefetch + tests
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / BasicRels.pm
CommitLineData
0567538f 1package DBICTest::Schema::BasicRels;
2
3use base 'DBIx::Class::Core';
4
5DBICTest::Schema::Artist->add_relationship(
6 cds => 'DBICTest::Schema::CD',
7 { 'foreign.artist' => 'self.artistid' },
64acc2bc 8 { order_by => 'year', join_type => 'LEFT', cascade_delete => 1, cascade_copy => 1, accessor => 'multi' }
0567538f 9);
10DBICTest::Schema::Artist->add_relationship(
11 twokeys => 'DBICTest::Schema::TwoKeys',
333cce60 12 { 'foreign.artist' => 'self.artistid' },
13 { cascade_copy => 1 }
0567538f 14);
15DBICTest::Schema::Artist->add_relationship(
16 onekeys => 'DBICTest::Schema::OneKey',
17 { 'foreign.artist' => 'self.artistid' }
18);
5efe4c79 19DBICTest::Schema::Artist->add_relationship(
20 artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap',
21 [{'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'}],
22 { accessor => 'multi' }
23);
24DBICTest::Schema::ArtistUndirectedMap->add_relationship(
25 'mapped_artists', 'DBICTest::Schema::Artist',
26 [{'foreign.artistid' => 'self.id1'}, {'foreign.artistid' => 'self.id2'}]
27);
0567538f 28DBICTest::Schema::CD->add_relationship(
29 artist => 'DBICTest::Schema::Artist',
30 { 'foreign.artistid' => 'self.artist' },
8452e496 31 { accessor => 'filter' },
0567538f 32);
33DBICTest::Schema::CD->add_relationship(
34 tracks => 'DBICTest::Schema::Track',
54540863 35 { 'foreign.cd' => 'self.cdid' },
36 { join_type => 'LEFT', cascade_delete => 1 }
0567538f 37);
38DBICTest::Schema::CD->add_relationship(
39 tags => 'DBICTest::Schema::Tag',
54540863 40 { 'foreign.cd' => 'self.cdid' },
f9cc31dd 41 { join_type => 'LEFT', cascade_delete => 1, cascade_copy => 1, accessor => 'multi' }
0567538f 42);
43#DBICTest::Schema::CD->might_have(liner_notes => 'DBICTest::Schema::LinerNotes' => qw/notes/);
44DBICTest::Schema::CD->add_relationship(
45 liner_notes => 'DBICTest::Schema::LinerNotes',
46 { 'foreign.liner_id' => 'self.cdid' },
8452e496 47 { join_type => 'LEFT', accessor => 'single' }
0567538f 48);
7411204b 49DBICTest::Schema::CD->add_relationship(
50 cd_to_producer => 'DBICTest::Schema::CD_to_Producer',
51 { 'foreign.cd' => 'self.cdid' },
52 { join_type => 'LEFT', cascade_delete => 1 }
53);
0567538f 54
55DBICTest::Schema::SelfRefAlias->add_relationship(
56 self_ref => 'DBICTest::Schema::SelfRef',
57 { 'foreign.id' => 'self.self_ref' },
58 { accessor => 'single' }
59
60);
61DBICTest::Schema::SelfRefAlias->add_relationship(
62 alias => 'DBICTest::Schema::SelfRef',
63 { 'foreign.id' => 'self.alias' },
64 { accessor => 'single' }
65);
66
67DBICTest::Schema::SelfRef->add_relationship(
68 aliases => 'DBICTest::Schema::SelfRefAlias',
69 { 'foreign.self_ref' => 'self.id' },
70 { accessor => 'multi' }
71);
72
73DBICTest::Schema::Tag->add_relationship(
74 cd => 'DBICTest::Schema::CD',
b3e8ac9b 75 { 'foreign.cdid' => 'self.cd' },
76 { accessor => 'single' }
0567538f 77);
78
79DBICTest::Schema::Track->add_relationship(
80 cd => 'DBICTest::Schema::CD',
35c2ee73 81 { 'foreign.cdid' => 'self.cd' }
0567538f 82);
83
84DBICTest::Schema::TwoKeys->add_relationship(
85 artist => 'DBICTest::Schema::Artist',
86 { 'foreign.artistid' => 'self.artist' }
87);
88DBICTest::Schema::TwoKeys->add_relationship(
89 cd => 'DBICTest::Schema::CD',
90 { 'foreign.cdid' => 'self.cd' }
91);
92
7411204b 93DBICTest::Schema::CD_to_Producer->add_relationship(
94 cd => 'DBICTest::Schema::CD',
95 { 'foreign.cdid' => 'self.cd' }
96);
97DBICTest::Schema::CD_to_Producer->add_relationship(
98 producer => 'DBICTest::Schema::Producer',
99 { 'foreign.producerid' => 'self.producer' }
100);
101
102# now the Helpers
103DBICTest::Schema::CD->many_to_many( 'producers', 'cd_to_producer', 'producer');
0f6ac8bb 104DBICTest::Schema::CD->many_to_many( 'producers_sorted', 'cd_to_producer', 'producer', { order_by => 'producer.name' });
7411204b 105
0567538f 1061;