1 package # hide from PAUSE
2 DBICTest::Schema::Artist;
7 use base 'DBICTest::BaseResult';
10 use DBICTest::Util 'check_customcond_args';
12 __PACKAGE__->table('artist');
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",
18 __PACKAGE__->add_columns(
20 data_type => 'integer',
21 is_auto_increment => 1,
24 data_type => 'varchar',
29 data_type => 'integer',
38 __PACKAGE__->set_primary_key('artistid');
39 __PACKAGE__->add_unique_constraint(['name']);
40 __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
41 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
44 __PACKAGE__->mk_classdata('field_name_for', {
45 artistid => 'primary key',
46 name => 'artist name',
49 # the undef condition in this rel is *deliberate*
50 # tests oddball legacy syntax
51 __PACKAGE__->has_many(
52 cds => 'DBICTest::Schema::CD', undef,
53 { order_by => { -asc => 'year'} },
56 __PACKAGE__->has_many(
57 cds_cref_cond => 'DBICTest::Schema::CD',
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;
65 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
67 $args->{self_result_object} && {
68 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, # keep old rowobj syntax as a test
74 __PACKAGE__->has_many(
75 cds_80s => 'DBICTest::Schema::CD',
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 :)
80 my $args = &check_customcond_args;
83 { "$args->{foreign_alias}.artist" => { '=' => \ "$args->{self_alias}.artistid" },
84 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
86 $args->{self_result_object} && {
87 "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_result_object}->artistid ] },
88 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
95 __PACKAGE__->has_many(
96 cds_84 => 'DBICTest::Schema::CD',
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 :)
101 my $args = &check_customcond_args;
104 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
105 "$args->{foreign_alias}.year" => 1984,
107 $args->{self_result_object} && {
108 "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid,
109 "$args->{foreign_alias}.year" => 1984,
116 __PACKAGE__->has_many(
117 cds_90s => 'DBICTest::Schema::CD',
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 :)
122 my $args = &check_customcond_args;
125 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
126 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
133 __PACKAGE__->has_many(
134 cds_unordered => 'DBICTest::Schema::CD'
136 __PACKAGE__->has_many(
137 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
140 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
141 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
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
149 __PACKAGE__->has_many(
150 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
152 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
154 __PACKAGE__->has_many(
155 cds_without_genre => 'DBICTest::Schema::CD',
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;
164 "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
165 "$args->{foreign_alias}.genreid" => undef,
166 }, $args->{self_result_object} && {
167 "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid,
168 "$args->{foreign_alias}.genreid" => undef,
174 sub sqlt_deploy_hook {
175 my ($self, $sqlt_table) = @_;
177 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
178 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
179 or die $sqlt_table->error;
184 my ($self, $name, $value) = @_;
185 $value = 'X '.$value if ($name eq 'name' && defined $value && $value =~ /(X )?store_column test/);
186 $self->next::method($name, $value);