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