1 package # hide from PAUSE
2 DBICTest::Schema::Artist;
7 use base 'DBICTest::BaseResult';
8 use DBICTest::Util 'check_customcond_args';
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',
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 :)
61 my $args = &check_customcond_args;
64 { "$args->{foreign_alias}.artist" => { '=' => \ "$args->{self_alias}.artistid" },
65 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
67 $args->{self_rowobj} && {
68 "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_rowobj}->artistid ] },
69 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
76 __PACKAGE__->has_many(
77 cds_84 => 'DBICTest::Schema::CD',
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 :)
82 my $args = &check_customcond_args;
85 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
86 "$args->{foreign_alias}.year" => 1984,
88 $args->{self_rowobj} && {
89 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
90 "$args->{foreign_alias}.year" => 1984,
97 __PACKAGE__->has_many(
98 cds_90s => 'DBICTest::Schema::CD',
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 :)
103 my $args = &check_customcond_args;
106 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
107 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
114 __PACKAGE__->has_many(
115 cds_unordered => 'DBICTest::Schema::CD'
117 __PACKAGE__->has_many(
118 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
121 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
122 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
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
130 __PACKAGE__->has_many(
131 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
133 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
135 __PACKAGE__->has_many(
136 cds_without_genre => 'DBICTest::Schema::CD',
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;
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,
155 sub sqlt_deploy_hook {
156 my ($self, $sqlt_table) = @_;
158 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
159 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
160 or die $sqlt_table->error;
165 my ($self, $name, $value) = @_;
166 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
167 $self->next::method($name, $value);