Commit | Line | Data |
8273e845 |
1 | package # hide from PAUSE |
c6d74d3e |
2 | DBICTest::Schema::Artist; |
a02675cd |
3 | |
4a233f30 |
4 | use warnings; |
5 | use strict; |
6 | |
660cf1be |
7 | use base qw/DBICTest::BaseResult/; |
6fbef4a4 |
8 | use Carp qw/confess/; |
a4e95946 |
9 | use Data::Query::ExprDeclare; |
a02675cd |
10 | |
ff657a43 |
11 | __PACKAGE__->table('artist'); |
a48e92d7 |
12 | __PACKAGE__->source_info({ |
13 | "source_info_key_A" => "source_info_value_A", |
14 | "source_info_key_B" => "source_info_value_B", |
15 | "source_info_key_C" => "source_info_value_C", |
16 | }); |
ff657a43 |
17 | __PACKAGE__->add_columns( |
0009fa49 |
18 | 'artistid' => { |
19 | data_type => 'integer', |
6e399b4f |
20 | is_auto_increment => 1, |
0009fa49 |
21 | }, |
22 | 'name' => { |
23 | data_type => 'varchar', |
cb561d1a |
24 | size => 100, |
0009fa49 |
25 | is_nullable => 1, |
26 | }, |
39da2a2b |
27 | rank => { |
28 | data_type => 'integer', |
29 | default_value => 13, |
30 | }, |
a0dd8679 |
31 | charfield => { |
32 | data_type => 'char', |
33 | size => 10, |
34 | is_nullable => 1, |
35 | }, |
0009fa49 |
36 | ); |
ff657a43 |
37 | __PACKAGE__->set_primary_key('artistid'); |
84f7e8a1 |
38 | __PACKAGE__->add_unique_constraint(['name']); |
1a625304 |
39 | __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test |
e29e2b27 |
40 | __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]); |
a02675cd |
41 | |
84f7e8a1 |
42 | |
90e6de6c |
43 | __PACKAGE__->mk_classdata('field_name_for', { |
44 | artistid => 'primary key', |
45 | name => 'artist name', |
46 | }); |
47 | |
98fcc1c0 |
48 | # the undef condition in this rel is *deliberate* |
49 | # tests oddball legacy syntax |
ff657a43 |
50 | __PACKAGE__->has_many( |
a4e95946 |
51 | cds => 'DBICTest::Schema::CD', |
52 | expr { $_->foreign->artist == $_->self->artistid }, |
d2fcb9b3 |
53 | { order_by => { -asc => 'year'} }, |
ff657a43 |
54 | ); |
2255d0be |
55 | |
56 | |
57 | __PACKAGE__->has_many( |
6c4f4d69 |
58 | cds_80s => 'DBICTest::Schema::CD', |
59 | sub { |
60 | my $args = shift; |
61 | |
6fbef4a4 |
62 | # This is for test purposes only. A regular user does not |
63 | # need to sanity check the passed-in arguments, this is what |
64 | # the tests are for :) |
65 | my @missing_args = grep { ! defined $args->{$_} } |
66 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
67 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
68 | if @missing_args; |
69 | |
6c4f4d69 |
70 | return ( |
71 | { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} }, |
72 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
73 | }, |
74 | $args->{self_rowobj} && { |
75 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
76 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
77 | } |
78 | ); |
79 | }, |
2255d0be |
80 | ); |
81 | |
abf8d91e |
82 | |
9aae3566 |
83 | __PACKAGE__->has_many( |
abf8d91e |
84 | cds_84 => 'DBICTest::Schema::CD', |
6c4f4d69 |
85 | sub { |
86 | my $args = shift; |
6fbef4a4 |
87 | |
88 | # This is for test purposes only. A regular user does not |
89 | # need to sanity check the passed-in arguments, this is what |
90 | # the tests are for :) |
91 | my @missing_args = grep { ! defined $args->{$_} } |
92 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
93 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
94 | if @missing_args; |
95 | |
6c4f4d69 |
96 | return ( |
97 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
98 | "$args->{foreign_alias}.year" => 1984, |
99 | }, |
100 | $args->{self_rowobj} && { |
101 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
102 | "$args->{foreign_alias}.year" => 1984, |
6c4f4d69 |
103 | } |
104 | ); |
d5a14c53 |
105 | } |
9aae3566 |
106 | ); |
107 | |
d5a14c53 |
108 | |
9aae3566 |
109 | __PACKAGE__->has_many( |
abf8d91e |
110 | cds_90s => 'DBICTest::Schema::CD', |
6c4f4d69 |
111 | sub { |
112 | my $args = shift; |
6fbef4a4 |
113 | |
114 | # This is for test purposes only. A regular user does not |
115 | # need to sanity check the passed-in arguments, this is what |
116 | # the tests are for :) |
117 | my @missing_args = grep { ! defined $args->{$_} } |
118 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
119 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
120 | if @missing_args; |
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 { |
155 | my $args = shift; |
156 | return ( |
157 | { |
158 | "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
159 | "$args->{foreign_alias}.genreid" => undef, |
160 | }, $args->{self_rowobj} && { |
161 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
162 | "$args->{foreign_alias}.genreid" => undef, |
163 | } |
164 | ), |
165 | }, |
166 | ); |
d5633096 |
167 | |
aaf2403d |
168 | sub sqlt_deploy_hook { |
169 | my ($self, $sqlt_table) = @_; |
170 | |
d6c79cb3 |
171 | if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) { |
1f5bf324 |
172 | $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] ) |
d6c79cb3 |
173 | or die $sqlt_table->error; |
174 | } |
aaf2403d |
175 | } |
c385ecea |
176 | |
52c53388 |
177 | sub store_column { |
178 | my ($self, $name, $value) = @_; |
a22688ab |
179 | $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/); |
52c53388 |
180 | $self->next::method($name, $value); |
181 | } |
182 | |
183 | |
a02675cd |
184 | 1; |