re-fix many_to_many and add tests
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / HelperRels.pm
1 package DBICTest::Schema::HelperRels;
2
3 use base 'DBIx::Class::Core';
4
5 DBICTest::Schema::Artist->has_many(cds => 'DBICTest::Schema::CD', undef,
6                                      { order_by => 'year' });
7 DBICTest::Schema::Artist->has_many(twokeys => 'DBICTest::Schema::TwoKeys');
8 DBICTest::Schema::Artist->has_many(onekeys => 'DBICTest::Schema::OneKey');
9
10 DBICTest::Schema::CD->belongs_to('artist', 'DBICTest::Schema::Artist');
11
12 DBICTest::Schema::CD->has_many(tracks => 'DBICTest::Schema::Track');
13 DBICTest::Schema::CD->has_many(tags => 'DBICTest::Schema::Tag');
14 DBICTest::Schema::CD->has_many(cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd');
15
16 DBICTest::Schema::CD->might_have(liner_notes => 'DBICTest::Schema::LinerNotes',
17                                   undef, { proxy => [ qw/notes/ ] });
18
19 DBICTest::Schema::SelfRefAlias->belongs_to(
20   self_ref => 'DBICTest::Schema::SelfRef');
21 DBICTest::Schema::SelfRefAlias->belongs_to(
22   alias => 'DBICTest::Schema::SelfRef');
23
24 DBICTest::Schema::SelfRef->has_many(
25   aliases => 'DBICTest::Schema::SelfRefAlias' => 'self_ref');
26
27 DBICTest::Schema::Tag->belongs_to('cd', 'DBICTest::Schema::CD');
28
29 DBICTest::Schema::Track->belongs_to('cd', 'DBICTest::Schema::CD');
30 DBICTest::Schema::Track->belongs_to('disc', 'DBICTest::Schema::CD', 'cd');
31
32 DBICTest::Schema::TwoKeys->belongs_to('artist', 'DBICTest::Schema::Artist');
33 DBICTest::Schema::TwoKeys->belongs_to('cd', 'DBICTest::Schema::CD');
34
35 DBICTest::Schema::CD_to_Producer->belongs_to(
36   'cd', 'DBICTest::Schema::CD',
37   { 'foreign.cdid' => 'self.cd' }
38 );
39 DBICTest::Schema::CD_to_Producer->belongs_to(
40   'producer', 'DBICTest::Schema::Producer',
41   { 'foreign.producerid' => 'self.producer' }
42 );
43 DBICTest::Schema::Artist->has_many(
44   'artist_undirected_maps', 'DBICTest::Schema::ArtistUndirectedMap',
45   [{'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'}]
46 );
47 DBICTest::Schema::ArtistUndirectedMap->belongs_to(
48   'artist1', 'DBICTest::Schema::Artist', 'id1');
49 DBICTest::Schema::ArtistUndirectedMap->belongs_to(
50   'artist2', 'DBICTest::Schema::Artist', 'id2');
51 DBICTest::Schema::ArtistUndirectedMap->has_many(
52   'mapped_artists', 'DBICTest::Schema::Artist',
53   [{'foreign.artistid' => 'self.id1'}, {'foreign.artistid' => 'self.id2'}]);
54
55 # now the Helpers
56 DBICTest::Schema::CD->many_to_many( 'producers', 'cd_to_producer', 'producer');
57 DBICTest::Schema::CD->many_to_many( 'producers_sorted', 'cd_to_producer', 'producer', { order_by => 'producer.name' });
58
59 1;