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 | |
54 | |
55 | __PACKAGE__->has_many( |
6c4f4d69 |
56 | cds_80s => 'DBICTest::Schema::CD', |
57 | sub { |
6fbef4a4 |
58 | # This is for test purposes only. A regular user does not |
59 | # need to sanity check the passed-in arguments, this is what |
60 | # the tests are for :) |
a3a17a15 |
61 | my $args = &check_customcond_args; |
6fbef4a4 |
62 | |
6c4f4d69 |
63 | return ( |
f8193780 |
64 | { "$args->{foreign_alias}.artist" => { '=' => \ "$args->{self_alias}.artistid" }, |
6c4f4d69 |
65 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
66 | }, |
67 | $args->{self_rowobj} && { |
f8193780 |
68 | "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_rowobj}->artistid ] }, |
6c4f4d69 |
69 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
70 | } |
71 | ); |
72 | }, |
2255d0be |
73 | ); |
74 | |
abf8d91e |
75 | |
9aae3566 |
76 | __PACKAGE__->has_many( |
abf8d91e |
77 | cds_84 => 'DBICTest::Schema::CD', |
6c4f4d69 |
78 | sub { |
6fbef4a4 |
79 | # This is for test purposes only. A regular user does not |
80 | # need to sanity check the passed-in arguments, this is what |
81 | # the tests are for :) |
a3a17a15 |
82 | my $args = &check_customcond_args; |
6fbef4a4 |
83 | |
6c4f4d69 |
84 | return ( |
85 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
86 | "$args->{foreign_alias}.year" => 1984, |
87 | }, |
88 | $args->{self_rowobj} && { |
89 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
90 | "$args->{foreign_alias}.year" => 1984, |
6c4f4d69 |
91 | } |
92 | ); |
d5a14c53 |
93 | } |
9aae3566 |
94 | ); |
95 | |
d5a14c53 |
96 | |
9aae3566 |
97 | __PACKAGE__->has_many( |
abf8d91e |
98 | cds_90s => 'DBICTest::Schema::CD', |
6c4f4d69 |
99 | sub { |
6fbef4a4 |
100 | # This is for test purposes only. A regular user does not |
101 | # need to sanity check the passed-in arguments, this is what |
102 | # the tests are for :) |
a3a17a15 |
103 | my $args = &check_customcond_args; |
6fbef4a4 |
104 | |
6c4f4d69 |
105 | return ( |
106 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
107 | "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 }, |
6c4f4d69 |
108 | } |
109 | ); |
9aae3566 |
110 | } |
111 | ); |
112 | |
2255d0be |
113 | |
c193d1d2 |
114 | __PACKAGE__->has_many( |
115 | cds_unordered => 'DBICTest::Schema::CD' |
116 | ); |
62d4dbae |
117 | __PACKAGE__->has_many( |
118 | cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD' |
119 | ); |
ff657a43 |
120 | |
121 | __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' ); |
122 | __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' ); |
123 | |
124 | __PACKAGE__->has_many( |
125 | artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap', |
126 | [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ], |
127 | { cascade_copy => 0 } # this would *so* not make sense |
128 | ); |
129 | |
d5633096 |
130 | __PACKAGE__->has_many( |
04e0d6ef |
131 | artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id' |
d5633096 |
132 | ); |
04e0d6ef |
133 | __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork'); |
d5633096 |
134 | |
18c294f4 |
135 | __PACKAGE__->has_many( |
136 | cds_without_genre => 'DBICTest::Schema::CD', |
137 | sub { |
a3a17a15 |
138 | # This is for test purposes only. A regular user does not |
139 | # need to sanity check the passed-in arguments, this is what |
140 | # the tests are for :) |
141 | my $args = &check_customcond_args; |
142 | |
18c294f4 |
143 | return ( |
144 | { |
145 | "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
146 | "$args->{foreign_alias}.genreid" => undef, |
147 | }, $args->{self_rowobj} && { |
148 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
149 | "$args->{foreign_alias}.genreid" => undef, |
150 | } |
151 | ), |
152 | }, |
153 | ); |
d5633096 |
154 | |
aaf2403d |
155 | sub sqlt_deploy_hook { |
156 | my ($self, $sqlt_table) = @_; |
157 | |
d6c79cb3 |
158 | if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) { |
1f5bf324 |
159 | $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] ) |
d6c79cb3 |
160 | or die $sqlt_table->error; |
161 | } |
aaf2403d |
162 | } |
c385ecea |
163 | |
52c53388 |
164 | sub store_column { |
165 | my ($self, $name, $value) = @_; |
a22688ab |
166 | $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/); |
52c53388 |
167 | $self->next::method($name, $value); |
168 | } |
169 | |
170 | |
a02675cd |
171 | 1; |