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