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