1 package # hide from PAUSE
2 DBICTest::Schema::Artist;
4 use base qw/DBICTest::BaseResult/;
7 __PACKAGE__->table('artist');
8 __PACKAGE__->source_info({
9 "source_info_key_A" => "source_info_value_A",
10 "source_info_key_B" => "source_info_value_B",
11 "source_info_key_C" => "source_info_value_C",
13 __PACKAGE__->add_columns(
15 data_type => 'integer',
16 is_auto_increment => 1,
19 data_type => 'varchar',
24 data_type => 'integer',
33 __PACKAGE__->set_primary_key('artistid');
34 __PACKAGE__->add_unique_constraint(['name']);
35 __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
36 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
39 __PACKAGE__->mk_classdata('field_name_for', {
40 artistid => 'primary key',
41 name => 'artist name',
44 __PACKAGE__->has_many(
45 cds => 'DBICTest::Schema::CD', undef,
46 { order_by => { -asc => 'year'} },
50 __PACKAGE__->has_many(
51 cds_80s => 'DBICTest::Schema::CD',
55 # This is for test purposes only. A regular user does not
56 # need to sanity check the passed-in arguments, this is what
57 # the tests are for :)
58 my @missing_args = grep { ! defined $args->{$_} }
59 qw/self_alias foreign_alias self_resultsource foreign_relname/;
60 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
64 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$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',
81 # This is for test purposes only. A regular user does not
82 # need to sanity check the passed-in arguments, this is what
83 # the tests are for :)
84 my @missing_args = grep { ! defined $args->{$_} }
85 qw/self_alias foreign_alias self_resultsource foreign_relname/;
86 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
90 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
91 "$args->{foreign_alias}.year" => 1984,
93 $args->{self_rowobj} && {
94 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
95 "$args->{foreign_alias}.year" => 1984,
102 __PACKAGE__->has_many(
103 cds_90s => 'DBICTest::Schema::CD',
107 # This is for test purposes only. A regular user does not
108 # need to sanity check the passed-in arguments, this is what
109 # the tests are for :)
110 my @missing_args = grep { ! defined $args->{$_} }
111 qw/self_alias foreign_alias self_resultsource foreign_relname/;
112 confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
116 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
117 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
124 __PACKAGE__->has_many(
125 cds_unordered => 'DBICTest::Schema::CD'
127 __PACKAGE__->has_many(
128 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
131 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
132 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
134 __PACKAGE__->has_many(
135 artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap',
136 [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ],
137 { cascade_copy => 0 } # this would *so* not make sense
140 __PACKAGE__->has_many(
141 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
143 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
146 sub sqlt_deploy_hook {
147 my ($self, $sqlt_table) = @_;
149 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
150 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
151 or die $sqlt_table->error;
156 my ($self, $name, $value) = @_;
157 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
158 $self->next::method($name, $value);