Commit | Line | Data |
c6d74d3e |
1 | package # hide from PAUSE |
2 | DBICTest::Schema::CD; |
a02675cd |
3 | |
660cf1be |
4 | use base qw/DBICTest::BaseResult/; |
a02675cd |
5 | |
ff657a43 |
6 | __PACKAGE__->table('cd'); |
7 | __PACKAGE__->add_columns( |
0009fa49 |
8 | 'cdid' => { |
9 | data_type => 'integer', |
10 | is_auto_increment => 1, |
11 | }, |
12 | 'artist' => { |
13 | data_type => 'integer', |
14 | }, |
15 | 'title' => { |
16 | data_type => 'varchar', |
cb561d1a |
17 | size => 100, |
0009fa49 |
18 | }, |
19 | 'year' => { |
20 | data_type => 'varchar', |
cb561d1a |
21 | size => 100, |
0009fa49 |
22 | }, |
370f2ba2 |
23 | 'genreid' => { |
4e0eaf64 |
24 | data_type => 'integer', |
25 | is_nullable => 1, |
a1cb5921 |
26 | }, |
27 | 'single_track' => { |
28 | data_type => 'integer', |
29 | is_nullable => 1, |
30 | is_foreign_key => 1, |
370f2ba2 |
31 | } |
0009fa49 |
32 | ); |
ff657a43 |
33 | __PACKAGE__->set_primary_key('cdid'); |
368a5228 |
34 | __PACKAGE__->add_unique_constraint([ qw/artist title/ ]); |
ff657a43 |
35 | |
e377d723 |
36 | __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', undef, { |
37 | is_deferrable => 1, |
e377d723 |
38 | }); |
ff657a43 |
39 | |
a1cb5921 |
40 | # in case this is a single-cd it promotes a track from another cd |
56b73f83 |
41 | __PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', 'single_track', |
42 | { join_type => 'left'} |
43 | ); |
a1cb5921 |
44 | |
ff657a43 |
45 | __PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' ); |
46 | __PACKAGE__->has_many( |
47 | tags => 'DBICTest::Schema::Tag', undef, |
48 | { order_by => 'tag' }, |
49 | ); |
50 | __PACKAGE__->has_many( |
51 | cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd' |
52 | ); |
53 | |
54 | __PACKAGE__->might_have( |
55 | liner_notes => 'DBICTest::Schema::LinerNotes', undef, |
56 | { proxy => [ qw/notes/ ] }, |
57 | ); |
4f6386b0 |
58 | __PACKAGE__->might_have(artwork => 'DBICTest::Schema::Artwork', 'cd_id'); |
cc9d96d0 |
59 | __PACKAGE__->has_one(mandatory_artwork => 'DBICTest::Schema::Artwork', 'cd_id'); |
4f6386b0 |
60 | |
ff657a43 |
61 | __PACKAGE__->many_to_many( producers => cd_to_producer => 'producer' ); |
62 | __PACKAGE__->many_to_many( |
63 | producers_sorted => cd_to_producer => 'producer', |
64 | { order_by => 'producer.name' }, |
65 | ); |
a02675cd |
66 | |
87310237 |
67 | __PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre', |
68 | { 'foreign.genreid' => 'self.genreid' }, |
a0dd8679 |
69 | { |
70 | join_type => 'left', |
71 | on_delete => 'SET NULL', |
72 | on_update => 'CASCADE', |
a0dd8679 |
73 | }, |
87310237 |
74 | ); |
370f2ba2 |
75 | |
cef1bdda |
76 | #This second relationship was added to test the short-circuiting of pointless |
77 | #queries provided by undef_on_null_fk. the relevant test in 66relationship.t |
78 | __PACKAGE__->belongs_to('genre_inefficient', 'DBICTest::Schema::Genre', |
79 | { 'foreign.genreid' => 'self.genreid' }, |
80 | { |
81 | join_type => 'left', |
82 | on_delete => 'SET NULL', |
83 | on_update => 'CASCADE', |
84 | undef_on_null_fk => 0, |
85 | }, |
86 | ); |
87 | |
a02675cd |
88 | 1; |