1 package # hide from PAUSE
2 DBICTest::Schema::Artist;
7 use base qw/DBICTest::BaseResult/;
10 __PACKAGE__->table('artist');
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",
16 __PACKAGE__->add_columns(
18 data_type => 'integer',
19 is_auto_increment => 1,
22 data_type => 'varchar',
27 data_type => 'integer',
36 __PACKAGE__->set_primary_key('artistid');
37 __PACKAGE__->add_unique_constraint(['name']);
38 __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
39 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
42 __PACKAGE__->mk_classdata('field_name_for', {
43 artistid => 'primary key',
44 name => 'artist name',
47 # the undef condition in this rel is *deliberate*
48 # tests oddball legacy syntax
49 __PACKAGE__->has_many(
50 cds => 'DBICTest::Schema::CD', undef,
51 { order_by => { -asc => 'year'} },
55 __PACKAGE__->has_many(
56 cds_80s => 'DBICTest::Schema::CD',
60 # This is for test purposes only. A regular user does not
61 # need to sanity check the passed-in arguments, this is what
62 # the tests are for :)
63 my @missing_args = grep { ! defined $args->{$_} }
64 qw/self_alias foreign_alias self_resultsource foreign_relname/;
65 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
69 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
70 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
72 $args->{self_rowobj} && {
73 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
74 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
81 __PACKAGE__->has_many(
82 cds_84 => 'DBICTest::Schema::CD',
86 # This is for test purposes only. A regular user does not
87 # need to sanity check the passed-in arguments, this is what
88 # the tests are for :)
89 my @missing_args = grep { ! defined $args->{$_} }
90 qw/self_alias foreign_alias self_resultsource foreign_relname/;
91 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
95 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
96 "$args->{foreign_alias}.year" => 1984,
98 $args->{self_rowobj} && {
99 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
100 "$args->{foreign_alias}.year" => 1984,
107 __PACKAGE__->has_many(
108 cds_90s => 'DBICTest::Schema::CD',
112 # This is for test purposes only. A regular user does not
113 # need to sanity check the passed-in arguments, this is what
114 # the tests are for :)
115 my @missing_args = grep { ! defined $args->{$_} }
116 qw/self_alias foreign_alias self_resultsource foreign_relname/;
117 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
121 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
122 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
129 __PACKAGE__->has_many(
130 cds_unordered => 'DBICTest::Schema::CD'
132 __PACKAGE__->has_many(
133 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
136 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
137 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
139 __PACKAGE__->has_many(
140 artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap',
141 [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ],
142 { cascade_copy => 0 } # this would *so* not make sense
145 __PACKAGE__->has_many(
146 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
148 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
150 __PACKAGE__->has_many(
151 cds_without_genre => 'DBICTest::Schema::CD',
156 "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
157 "$args->{foreign_alias}.genreid" => undef,
158 }, $args->{self_rowobj} && {
159 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
160 "$args->{foreign_alias}.genreid" => undef,
166 sub sqlt_deploy_hook {
167 my ($self, $sqlt_table) = @_;
169 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
170 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
171 or die $sqlt_table->error;
176 my ($self, $name, $value) = @_;
177 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
178 $self->next::method($name, $value);