Commit | Line | Data |
b5c8410c |
1 | package # hide from PAUSE |
c6d74d3e |
2 | DBICTest::Schema::Track; |
a02675cd |
3 | |
660cf1be |
4 | use base qw/DBICTest::BaseResult/; |
6fbef4a4 |
5 | use Carp qw/confess/; |
6 | |
1ceafb0c |
7 | __PACKAGE__->load_components(qw/InflateColumn::DateTime Ordered/); |
a02675cd |
8 | |
ff657a43 |
9 | __PACKAGE__->table('track'); |
10 | __PACKAGE__->add_columns( |
0009fa49 |
11 | 'trackid' => { |
12 | data_type => 'integer', |
13 | is_auto_increment => 1, |
14 | }, |
15 | 'cd' => { |
16 | data_type => 'integer', |
17 | }, |
18 | 'position' => { |
c1d7087d |
19 | data_type => 'int', |
91b0fbd7 |
20 | accessor => 'pos', |
0009fa49 |
21 | }, |
22 | 'title' => { |
23 | data_type => 'varchar', |
cb561d1a |
24 | size => 100, |
0009fa49 |
25 | }, |
43556c5d |
26 | last_updated_on => { |
27 | data_type => 'datetime', |
28 | accessor => 'updated_date', |
29 | is_nullable => 1 |
30 | }, |
abc914bd |
31 | last_updated_at => { |
32 | data_type => 'datetime', |
33 | is_nullable => 1 |
34 | }, |
0009fa49 |
35 | ); |
ff657a43 |
36 | __PACKAGE__->set_primary_key('trackid'); |
37 | |
365d06b7 |
38 | __PACKAGE__->add_unique_constraint([ qw/cd position/ ]); |
39 | __PACKAGE__->add_unique_constraint([ qw/cd title/ ]); |
40 | |
1ceafb0c |
41 | __PACKAGE__->position_column ('position'); |
42 | __PACKAGE__->grouping_column ('cd'); |
43 | |
44 | |
97c96475 |
45 | __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { |
46 | proxy => { cd_title => 'title' }, |
47 | }); |
48 | __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd', { |
49 | proxy => 'year' |
50 | }); |
a02675cd |
51 | |
a1cb5921 |
52 | __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' ); |
4f6386b0 |
53 | __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' ); |
a1cb5921 |
54 | |
18129e81 |
55 | __PACKAGE__->belongs_to( |
56 | "year1999cd", |
57 | "DBICTest::Schema::Year1999CDs", |
58 | { "foreign.cdid" => "self.cd" }, |
f549392f |
59 | { join_type => 'left' }, # the relationship is of course optional |
18129e81 |
60 | ); |
61 | __PACKAGE__->belongs_to( |
62 | "year2000cd", |
63 | "DBICTest::Schema::Year2000CDs", |
64 | { "foreign.cdid" => "self.cd" }, |
f549392f |
65 | { join_type => 'left' }, |
18129e81 |
66 | ); |
67 | |
b5c8410c |
68 | __PACKAGE__->might_have ( |
6c4f4d69 |
69 | next_track => __PACKAGE__, |
70 | sub { |
71 | my $args = shift; |
6fbef4a4 |
72 | |
73 | # This is for test purposes only. A regular user does not |
74 | # need to sanity check the passed-in arguments, this is what |
75 | # the tests are for :) |
76 | my @missing_args = grep { ! defined $args->{$_} } |
77 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
78 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
79 | if @missing_args; |
80 | |
6c4f4d69 |
81 | return ( |
82 | { "$args->{foreign_alias}.cd" => { -ident => "$args->{self_alias}.cd" }, |
83 | "$args->{foreign_alias}.position" => { '>' => { -ident => "$args->{self_alias}.position" } }, |
84 | }, |
85 | $args->{self_rowobj} && { |
86 | "$args->{foreign_alias}.cd" => $args->{self_rowobj}->cd, |
87 | "$args->{foreign_alias}.position" => { '>' => $args->{self_rowobj}->position }, |
88 | } |
89 | ) |
90 | } |
b5c8410c |
91 | ); |
92 | |
a02675cd |
93 | 1; |