Commit | Line | Data |
b5c8410c |
1 | package # hide from PAUSE |
c6d74d3e |
2 | DBICTest::Schema::Track; |
a02675cd |
3 | |
660cf1be |
4 | use base qw/DBICTest::BaseResult/; |
1ceafb0c |
5 | __PACKAGE__->load_components(qw/InflateColumn::DateTime Ordered/); |
a02675cd |
6 | |
ff657a43 |
7 | __PACKAGE__->table('track'); |
8 | __PACKAGE__->add_columns( |
0009fa49 |
9 | 'trackid' => { |
10 | data_type => 'integer', |
11 | is_auto_increment => 1, |
12 | }, |
13 | 'cd' => { |
14 | data_type => 'integer', |
15 | }, |
16 | 'position' => { |
c1d7087d |
17 | data_type => 'int', |
91b0fbd7 |
18 | accessor => 'pos', |
0009fa49 |
19 | }, |
20 | 'title' => { |
21 | data_type => 'varchar', |
cb561d1a |
22 | size => 100, |
0009fa49 |
23 | }, |
43556c5d |
24 | last_updated_on => { |
25 | data_type => 'datetime', |
26 | accessor => 'updated_date', |
27 | is_nullable => 1 |
28 | }, |
abc914bd |
29 | last_updated_at => { |
30 | data_type => 'datetime', |
31 | is_nullable => 1 |
32 | }, |
0009fa49 |
33 | ); |
ff657a43 |
34 | __PACKAGE__->set_primary_key('trackid'); |
35 | |
365d06b7 |
36 | __PACKAGE__->add_unique_constraint([ qw/cd position/ ]); |
37 | __PACKAGE__->add_unique_constraint([ qw/cd title/ ]); |
38 | |
1ceafb0c |
39 | __PACKAGE__->position_column ('position'); |
40 | __PACKAGE__->grouping_column ('cd'); |
41 | |
42 | |
97c96475 |
43 | __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { |
44 | proxy => { cd_title => 'title' }, |
45 | }); |
46 | __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd', { |
47 | proxy => 'year' |
48 | }); |
a02675cd |
49 | |
a1cb5921 |
50 | __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' ); |
4f6386b0 |
51 | __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' ); |
a1cb5921 |
52 | |
18129e81 |
53 | __PACKAGE__->belongs_to( |
54 | "year1999cd", |
55 | "DBICTest::Schema::Year1999CDs", |
56 | { "foreign.cdid" => "self.cd" }, |
f549392f |
57 | { join_type => 'left' }, # the relationship is of course optional |
18129e81 |
58 | ); |
59 | __PACKAGE__->belongs_to( |
60 | "year2000cd", |
61 | "DBICTest::Schema::Year2000CDs", |
62 | { "foreign.cdid" => "self.cd" }, |
f549392f |
63 | { join_type => 'left' }, |
18129e81 |
64 | ); |
65 | |
b5c8410c |
66 | __PACKAGE__->might_have ( |
67 | 'next_track', |
68 | __PACKAGE__, |
69 | sub { |
70 | my ( $self_alias, $rel_alias, $self_rsrc, $rel_name ) = @_; |
71 | return { |
72 | "${self_alias}.cd" => \ "${rel_alias}.cd", |
73 | "${self_alias}.position" => { '<', \ "${rel_alias}.position" }, |
74 | }; |
75 | }, |
76 | ); |
77 | |
a02675cd |
78 | 1; |