has_many prefetch works. no, seriously
[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', undef,
14                                  { order_by => 'tag' });
15 DBICTest::Schema::CD->has_many(cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd');
16
17 DBICTest::Schema::CD->might_have(liner_notes => 'DBICTest::Schema::LinerNotes',
18                                   undef, { proxy => [ qw/notes/ ] });
19
20 DBICTest::Schema::SelfRefAlias->belongs_to(
21   self_ref => 'DBICTest::Schema::SelfRef');
22 DBICTest::Schema::SelfRefAlias->belongs_to(
23   alias => 'DBICTest::Schema::SelfRef');
24
25 DBICTest::Schema::SelfRef->has_many(
26   aliases => 'DBICTest::Schema::SelfRefAlias' => 'self_ref');
27
28 DBICTest::Schema::Tag->belongs_to('cd', 'DBICTest::Schema::CD');
29
30 DBICTest::Schema::Track->belongs_to('cd', 'DBICTest::Schema::CD');
31 DBICTest::Schema::Track->belongs_to('disc', 'DBICTest::Schema::CD', 'cd');
32
33 DBICTest::Schema::TwoKeys->belongs_to('artist', 'DBICTest::Schema::Artist');
34 DBICTest::Schema::TwoKeys->belongs_to('cd', 'DBICTest::Schema::CD');
35
36 DBICTest::Schema::CD_to_Producer->belongs_to(
37   'cd', 'DBICTest::Schema::CD',
38   { 'foreign.cdid' => 'self.cd' }
39 );
40 DBICTest::Schema::CD_to_Producer->belongs_to(
41   'producer', 'DBICTest::Schema::Producer',
42   { 'foreign.producerid' => 'self.producer' }
43 );
44 DBICTest::Schema::Artist->has_many(
45   'artist_undirected_maps', 'DBICTest::Schema::ArtistUndirectedMap',
46   [{'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'}],
47   { cascade_copy => 0 } # this would *so* not make sense
48 );
49 DBICTest::Schema::ArtistUndirectedMap->belongs_to(
50   'artist1', 'DBICTest::Schema::Artist', 'id1');
51 DBICTest::Schema::ArtistUndirectedMap->belongs_to(
52   'artist2', 'DBICTest::Schema::Artist', 'id2');
53 DBICTest::Schema::ArtistUndirectedMap->has_many(
54   'mapped_artists', 'DBICTest::Schema::Artist',
55   [{'foreign.artistid' => 'self.id1'}, {'foreign.artistid' => 'self.id2'}]);
56
57 # now the Helpers
58 DBICTest::Schema::CD->many_to_many( 'producers', 'cd_to_producer', 'producer');
59 DBICTest::Schema::CD->many_to_many( 'producers_sorted', 'cd_to_producer', 'producer', { order_by => 'producer.name' });
60
61 1;