Commit | Line | Data |
b5c8410c |
1 | package # hide from PAUSE |
c6d74d3e |
2 | DBICTest::Schema::Track; |
a02675cd |
3 | |
4a233f30 |
4 | use warnings; |
5 | use strict; |
6 | |
a3a17a15 |
7 | use base 'DBICTest::BaseResult'; |
8 | use DBICTest::Util 'check_customcond_args'; |
6fbef4a4 |
9 | |
a267ea85 |
10 | __PACKAGE__->load_components(qw{ |
11 | +DBICTest::DeployComponent |
12 | InflateColumn::DateTime |
13 | Ordered |
14 | }); |
a02675cd |
15 | |
ff657a43 |
16 | __PACKAGE__->table('track'); |
17 | __PACKAGE__->add_columns( |
0009fa49 |
18 | 'trackid' => { |
19 | data_type => 'integer', |
20 | is_auto_increment => 1, |
21 | }, |
22 | 'cd' => { |
23 | data_type => 'integer', |
24 | }, |
25 | 'position' => { |
c1d7087d |
26 | data_type => 'int', |
91b0fbd7 |
27 | accessor => 'pos', |
0009fa49 |
28 | }, |
29 | 'title' => { |
30 | data_type => 'varchar', |
cb561d1a |
31 | size => 100, |
0009fa49 |
32 | }, |
43556c5d |
33 | last_updated_on => { |
34 | data_type => 'datetime', |
35 | accessor => 'updated_date', |
36 | is_nullable => 1 |
37 | }, |
abc914bd |
38 | last_updated_at => { |
39 | data_type => 'datetime', |
40 | is_nullable => 1 |
41 | }, |
0009fa49 |
42 | ); |
ff657a43 |
43 | __PACKAGE__->set_primary_key('trackid'); |
44 | |
365d06b7 |
45 | __PACKAGE__->add_unique_constraint([ qw/cd position/ ]); |
46 | __PACKAGE__->add_unique_constraint([ qw/cd title/ ]); |
47 | |
1ceafb0c |
48 | __PACKAGE__->position_column ('position'); |
49 | __PACKAGE__->grouping_column ('cd'); |
50 | |
98fcc1c0 |
51 | # the undef condition in this rel is *deliberate* |
52 | # tests oddball legacy syntax |
97c96475 |
53 | __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { |
54 | proxy => { cd_title => 'title' }, |
55 | }); |
8c7c8398 |
56 | # custom condition coderef |
57 | __PACKAGE__->belongs_to( cd_cref_cond => 'DBICTest::Schema::CD', |
58 | sub { |
59 | # This is for test purposes only. A regular user does not |
60 | # need to sanity check the passed-in arguments, this is what |
61 | # the tests are for :) |
62 | my $args = &check_customcond_args; |
63 | |
64 | return ( |
65 | { |
66 | "$args->{foreign_alias}.cdid" => { -ident => "$args->{self_alias}.cd" }, |
67 | }, |
68 | |
ef0845ba |
69 | ! $args->{self_result_object} ? () : { |
7df2b5df |
70 | "$args->{foreign_alias}.cdid" => $args->{self_result_object}->get_column('cd') |
ef0845ba |
71 | }, |
8c7c8398 |
72 | |
e884e5d9 |
73 | ! $args->{foreign_values} ? () : { |
74 | "$args->{self_alias}.cd" => $args->{foreign_values}{cdid} |
ef0845ba |
75 | }, |
8c7c8398 |
76 | ); |
77 | } |
78 | ); |
97c96475 |
79 | __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd', { |
80 | proxy => 'year' |
81 | }); |
a02675cd |
82 | |
a1cb5921 |
83 | __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' ); |
4f6386b0 |
84 | __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' ); |
a1cb5921 |
85 | |
18129e81 |
86 | __PACKAGE__->belongs_to( |
87 | "year1999cd", |
88 | "DBICTest::Schema::Year1999CDs", |
98fcc1c0 |
89 | 'cd', |
f549392f |
90 | { join_type => 'left' }, # the relationship is of course optional |
18129e81 |
91 | ); |
92 | __PACKAGE__->belongs_to( |
93 | "year2000cd", |
94 | "DBICTest::Schema::Year2000CDs", |
98fcc1c0 |
95 | 'cd', |
f549392f |
96 | { join_type => 'left' }, |
18129e81 |
97 | ); |
98 | |
bdf6d515 |
99 | __PACKAGE__->has_many ( |
100 | next_tracks => __PACKAGE__, |
6c4f4d69 |
101 | sub { |
6fbef4a4 |
102 | # This is for test purposes only. A regular user does not |
103 | # need to sanity check the passed-in arguments, this is what |
104 | # the tests are for :) |
a3a17a15 |
105 | my $args = &check_customcond_args; |
6fbef4a4 |
106 | |
6c4f4d69 |
107 | return ( |
108 | { "$args->{foreign_alias}.cd" => { -ident => "$args->{self_alias}.cd" }, |
109 | "$args->{foreign_alias}.position" => { '>' => { -ident => "$args->{self_alias}.position" } }, |
110 | }, |
98def3ef |
111 | $args->{self_result_object} && { |
112 | "$args->{foreign_alias}.cd" => $args->{self_result_object}->get_column('cd'), |
113 | "$args->{foreign_alias}.position" => { '>' => $args->{self_result_object}->pos }, |
6c4f4d69 |
114 | } |
115 | ) |
116 | } |
b5c8410c |
117 | ); |
118 | |
c200d949 |
119 | __PACKAGE__->has_many ( |
120 | deliberately_broken_all_cd_tracks => __PACKAGE__, |
121 | sub { |
122 | # This is for test purposes only. A regular user does not |
123 | # need to sanity check the passed-in arguments, this is what |
124 | # the tests are for :) |
125 | my $args = &check_customcond_args; |
126 | |
127 | return { |
128 | "$args->{foreign_alias}.cd" => "$args->{self_alias}.cd" |
129 | }; |
130 | } |
131 | ); |
132 | |
a267ea85 |
133 | our $hook_cb; |
134 | |
135 | sub sqlt_deploy_hook { |
136 | my $class = shift; |
137 | |
138 | $hook_cb->($class, @_) if $hook_cb; |
139 | $class->next::method(@_) if $class->next::can; |
140 | } |
141 | |
a02675cd |
142 | 1; |