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