Commit | Line | Data |
8273e845 |
1 | package # hide from PAUSE |
c6d74d3e |
2 | DBICTest::Schema::Artist; |
a02675cd |
3 | |
4a233f30 |
4 | use warnings; |
5 | use strict; |
6 | |
a3a17a15 |
7 | use base 'DBICTest::BaseResult'; |
8 | use DBICTest::Util 'check_customcond_args'; |
a02675cd |
9 | |
ff657a43 |
10 | __PACKAGE__->table('artist'); |
a48e92d7 |
11 | __PACKAGE__->source_info({ |
12 | "source_info_key_A" => "source_info_value_A", |
13 | "source_info_key_B" => "source_info_value_B", |
14 | "source_info_key_C" => "source_info_value_C", |
15 | }); |
ff657a43 |
16 | __PACKAGE__->add_columns( |
0009fa49 |
17 | 'artistid' => { |
18 | data_type => 'integer', |
6e399b4f |
19 | is_auto_increment => 1, |
0009fa49 |
20 | }, |
21 | 'name' => { |
22 | data_type => 'varchar', |
cb561d1a |
23 | size => 100, |
0009fa49 |
24 | is_nullable => 1, |
25 | }, |
39da2a2b |
26 | rank => { |
27 | data_type => 'integer', |
28 | default_value => 13, |
29 | }, |
a0dd8679 |
30 | charfield => { |
31 | data_type => 'char', |
32 | size => 10, |
33 | is_nullable => 1, |
34 | }, |
0009fa49 |
35 | ); |
ff657a43 |
36 | __PACKAGE__->set_primary_key('artistid'); |
84f7e8a1 |
37 | __PACKAGE__->add_unique_constraint(['name']); |
1a625304 |
38 | __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test |
e29e2b27 |
39 | __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]); |
a02675cd |
40 | |
84f7e8a1 |
41 | |
90e6de6c |
42 | __PACKAGE__->mk_classdata('field_name_for', { |
43 | artistid => 'primary key', |
44 | name => 'artist name', |
45 | }); |
46 | |
98fcc1c0 |
47 | # the undef condition in this rel is *deliberate* |
48 | # tests oddball legacy syntax |
ff657a43 |
49 | __PACKAGE__->has_many( |
50 | cds => 'DBICTest::Schema::CD', undef, |
d2fcb9b3 |
51 | { order_by => { -asc => 'year'} }, |
ff657a43 |
52 | ); |
2255d0be |
53 | |
8c7c8398 |
54 | __PACKAGE__->has_many( |
55 | cds_cref_cond => 'DBICTest::Schema::CD', |
56 | sub { |
57 | # This is for test purposes only. A regular user does not |
58 | # need to sanity check the passed-in arguments, this is what |
59 | # the tests are for :) |
60 | my $args = &check_customcond_args; |
61 | |
62 | return ( |
63 | { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} }, |
64 | }, |
65 | $args->{self_rowobj} && { |
66 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
67 | } |
68 | ); |
69 | }, |
70 | ); |
2255d0be |
71 | |
72 | __PACKAGE__->has_many( |
6c4f4d69 |
73 | cds_80s => 'DBICTest::Schema::CD', |
74 | sub { |
6fbef4a4 |
75 | # This is for test purposes only. A regular user does not |
76 | # need to sanity check the passed-in arguments, this is what |
77 | # the tests are for :) |
a3a17a15 |
78 | my $args = &check_customcond_args; |
6fbef4a4 |
79 | |
6c4f4d69 |
80 | return ( |
f8193780 |
81 | { "$args->{foreign_alias}.artist" => { '=' => \ "$args->{self_alias}.artistid" }, |
6c4f4d69 |
82 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
83 | }, |
84 | $args->{self_rowobj} && { |
f8193780 |
85 | "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_rowobj}->artistid ] }, |
6c4f4d69 |
86 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
87 | } |
88 | ); |
89 | }, |
2255d0be |
90 | ); |
91 | |
abf8d91e |
92 | |
9aae3566 |
93 | __PACKAGE__->has_many( |
abf8d91e |
94 | cds_84 => 'DBICTest::Schema::CD', |
6c4f4d69 |
95 | sub { |
6fbef4a4 |
96 | # This is for test purposes only. A regular user does not |
97 | # need to sanity check the passed-in arguments, this is what |
98 | # the tests are for :) |
a3a17a15 |
99 | my $args = &check_customcond_args; |
6fbef4a4 |
100 | |
6c4f4d69 |
101 | return ( |
102 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
103 | "$args->{foreign_alias}.year" => 1984, |
104 | }, |
105 | $args->{self_rowobj} && { |
106 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
107 | "$args->{foreign_alias}.year" => 1984, |
6c4f4d69 |
108 | } |
109 | ); |
d5a14c53 |
110 | } |
9aae3566 |
111 | ); |
112 | |
d5a14c53 |
113 | |
9aae3566 |
114 | __PACKAGE__->has_many( |
abf8d91e |
115 | cds_90s => 'DBICTest::Schema::CD', |
6c4f4d69 |
116 | sub { |
6fbef4a4 |
117 | # This is for test purposes only. A regular user does not |
118 | # need to sanity check the passed-in arguments, this is what |
119 | # the tests are for :) |
a3a17a15 |
120 | my $args = &check_customcond_args; |
6fbef4a4 |
121 | |
6c4f4d69 |
122 | return ( |
123 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
124 | "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 }, |
6c4f4d69 |
125 | } |
126 | ); |
9aae3566 |
127 | } |
128 | ); |
129 | |
2255d0be |
130 | |
c193d1d2 |
131 | __PACKAGE__->has_many( |
132 | cds_unordered => 'DBICTest::Schema::CD' |
133 | ); |
62d4dbae |
134 | __PACKAGE__->has_many( |
135 | cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD' |
136 | ); |
ff657a43 |
137 | |
138 | __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' ); |
139 | __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' ); |
140 | |
141 | __PACKAGE__->has_many( |
142 | artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap', |
143 | [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ], |
144 | { cascade_copy => 0 } # this would *so* not make sense |
145 | ); |
146 | |
d5633096 |
147 | __PACKAGE__->has_many( |
04e0d6ef |
148 | artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id' |
d5633096 |
149 | ); |
04e0d6ef |
150 | __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork'); |
d5633096 |
151 | |
18c294f4 |
152 | __PACKAGE__->has_many( |
153 | cds_without_genre => 'DBICTest::Schema::CD', |
154 | sub { |
a3a17a15 |
155 | # This is for test purposes only. A regular user does not |
156 | # need to sanity check the passed-in arguments, this is what |
157 | # the tests are for :) |
158 | my $args = &check_customcond_args; |
159 | |
18c294f4 |
160 | return ( |
161 | { |
162 | "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
163 | "$args->{foreign_alias}.genreid" => undef, |
164 | }, $args->{self_rowobj} && { |
165 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
166 | "$args->{foreign_alias}.genreid" => undef, |
167 | } |
168 | ), |
169 | }, |
170 | ); |
d5633096 |
171 | |
aaf2403d |
172 | sub sqlt_deploy_hook { |
173 | my ($self, $sqlt_table) = @_; |
174 | |
d6c79cb3 |
175 | if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) { |
1f5bf324 |
176 | $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] ) |
d6c79cb3 |
177 | or die $sqlt_table->error; |
178 | } |
aaf2403d |
179 | } |
c385ecea |
180 | |
52c53388 |
181 | sub store_column { |
182 | my ($self, $name, $value) = @_; |
a22688ab |
183 | $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/); |
52c53388 |
184 | $self->next::method($name, $value); |
185 | } |
186 | |
187 | |
a02675cd |
188 | 1; |