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