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 __PACKAGE__->has_many(
48 cds => 'DBICTest::Schema::CD', undef,
49 { order_by => { -asc => 'year'} },
53 __PACKAGE__->has_many(
54 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 @missing_args = grep { ! defined $args->{$_} }
62 qw/self_alias foreign_alias self_resultsource foreign_relname/;
63 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
67 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
68 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
70 $args->{self_rowobj} && {
71 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
72 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
79 __PACKAGE__->has_many(
80 cds_84 => 'DBICTest::Schema::CD',
84 # This is for test purposes only. A regular user does not
85 # need to sanity check the passed-in arguments, this is what
86 # the tests are for :)
87 my @missing_args = grep { ! defined $args->{$_} }
88 qw/self_alias foreign_alias self_resultsource foreign_relname/;
89 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
93 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
94 "$args->{foreign_alias}.year" => 1984,
96 $args->{self_rowobj} && {
97 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
98 "$args->{foreign_alias}.year" => 1984,
105 __PACKAGE__->has_many(
106 cds_90s => 'DBICTest::Schema::CD',
110 # This is for test purposes only. A regular user does not
111 # need to sanity check the passed-in arguments, this is what
112 # the tests are for :)
113 my @missing_args = grep { ! defined $args->{$_} }
114 qw/self_alias foreign_alias self_resultsource foreign_relname/;
115 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
119 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
120 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
127 __PACKAGE__->has_many(
128 cds_unordered => 'DBICTest::Schema::CD'
130 __PACKAGE__->has_many(
131 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
134 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
135 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
137 __PACKAGE__->has_many(
138 artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap',
139 [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ],
140 { cascade_copy => 0 } # this would *so* not make sense
143 __PACKAGE__->has_many(
144 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
146 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
149 sub sqlt_deploy_hook {
150 my ($self, $sqlt_table) = @_;
152 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
153 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
154 or die $sqlt_table->error;
159 my ($self, $name, $value) = @_;
160 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
161 $self->next::method($name, $value);