Double an existing might_have test as has_one
[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 __PACKAGE__->table('cd');
7 __PACKAGE__->add_columns(
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',
17     size      => 100,
18   },
19   'year' => {
20     data_type => 'varchar',
21     size      => 100,
22   },
23   'genreid' => { 
24     data_type => 'integer',
25     is_nullable => 1,
26   },
27   'single_track' => {
28     data_type => 'integer',
29     is_nullable => 1,
30     is_foreign_key => 1,
31   }
32 );
33 __PACKAGE__->set_primary_key('cdid');
34 __PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
35
36 __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', undef, { 
37     is_deferrable => 1, 
38 });
39
40 # in case this is a single-cd it promotes a track from another cd
41 __PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', 'single_track', 
42     { join_type => 'left'} 
43 );
44
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 );
58 __PACKAGE__->might_have(artwork => 'DBICTest::Schema::Artwork', 'cd_id');
59 __PACKAGE__->has_one(mandatory_artwork => 'DBICTest::Schema::Artwork', 'cd_id');
60
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 );
66
67 __PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre',
68     { 'foreign.genreid' => 'self.genreid' },
69     {
70         join_type => 'left',
71         on_delete => 'SET NULL',
72         on_update => 'CASCADE',
73     },
74 );
75
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
88 1;