separated table ref test out, changed CDTableRef to a view with less rels
[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
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');
59
ff657a43 60__PACKAGE__->many_to_many( producers => cd_to_producer => 'producer' );
61__PACKAGE__->many_to_many(
62 producers_sorted => cd_to_producer => 'producer',
63 { order_by => 'producer.name' },
64);
a02675cd 65
87310237 66__PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre',
67 { 'foreign.genreid' => 'self.genreid' },
a0dd8679 68 {
69 join_type => 'left',
70 on_delete => 'SET NULL',
71 on_update => 'CASCADE',
a0dd8679 72 },
87310237 73);
370f2ba2 74
cef1bdda 75#This second relationship was added to test the short-circuiting of pointless
76#queries provided by undef_on_null_fk. the relevant test in 66relationship.t
77__PACKAGE__->belongs_to('genre_inefficient', 'DBICTest::Schema::Genre',
78 { 'foreign.genreid' => 'self.genreid' },
79 {
80 join_type => 'left',
81 on_delete => 'SET NULL',
82 on_update => 'CASCADE',
83 undef_on_null_fk => 0,
84 },
85);
86
a02675cd 871;