1 package # hide from PAUSE
2 DBICTest::Schema::Artist;
7 use base qw/DBICTest::BaseResult/;
9 use Data::Query::ExprDeclare;
11 __PACKAGE__->table('artist');
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",
17 __PACKAGE__->add_columns(
19 data_type => 'integer',
20 is_auto_increment => 1,
23 data_type => 'varchar',
28 data_type => 'integer',
37 __PACKAGE__->set_primary_key('artistid');
38 __PACKAGE__->add_unique_constraint(['name']);
39 __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
40 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
43 __PACKAGE__->mk_classdata('field_name_for', {
44 artistid => 'primary key',
45 name => 'artist name',
48 # the undef condition in this rel is *deliberate*
49 # tests oddball legacy syntax
50 __PACKAGE__->has_many(
51 cds => 'DBICTest::Schema::CD',
52 expr { $_->foreign->artist == $_->self->artistid },
53 { order_by => { -asc => 'year'} },
57 __PACKAGE__->has_many(
58 cds_80s => 'DBICTest::Schema::CD',
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"
71 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
72 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
74 $args->{self_rowobj} && {
75 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
76 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
83 __PACKAGE__->has_many(
84 cds_84 => 'DBICTest::Schema::CD',
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"
97 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
98 "$args->{foreign_alias}.year" => 1984,
100 $args->{self_rowobj} && {
101 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
102 "$args->{foreign_alias}.year" => 1984,
109 __PACKAGE__->has_many(
110 cds_90s => 'DBICTest::Schema::CD',
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"
123 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
124 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
131 __PACKAGE__->has_many(
132 cds_unordered => 'DBICTest::Schema::CD'
134 __PACKAGE__->has_many(
135 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
138 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
139 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
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
147 __PACKAGE__->has_many(
148 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
150 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
152 __PACKAGE__->has_many(
153 cds_without_genre => 'DBICTest::Schema::CD',
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,
168 sub sqlt_deploy_hook {
169 my ($self, $sqlt_table) = @_;
171 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
172 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
173 or die $sqlt_table->error;
178 my ($self, $name, $value) = @_;
179 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
180 $self->next::method($name, $value);