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