1 package # hide from PAUSE
2 DBICTest::Schema::Artist;
4 use base qw/DBICTest::BaseResult/;
6 __PACKAGE__->table('artist');
7 __PACKAGE__->source_info({
8 "source_info_key_A" => "source_info_value_A",
9 "source_info_key_B" => "source_info_value_B",
10 "source_info_key_C" => "source_info_value_C",
12 __PACKAGE__->add_columns(
14 data_type => 'integer',
15 is_auto_increment => 1,
18 data_type => 'varchar',
23 data_type => 'integer',
32 __PACKAGE__->set_primary_key('artistid');
33 __PACKAGE__->add_unique_constraint(['name']);
34 __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
35 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
38 __PACKAGE__->mk_classdata('field_name_for', {
39 artistid => 'primary key',
40 name => 'artist name',
43 __PACKAGE__->has_many(
44 cds => 'DBICTest::Schema::CD', undef,
45 { order_by => { -asc => 'year'} },
49 __PACKAGE__->has_many(
50 cds_80s => 'DBICTest::Schema::CD',
55 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
56 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
58 $args->{self_rowobj} && {
59 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
60 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
66 __PACKAGE__->has_many(
67 cds_80s_noopt => 'DBICTest::Schema::CD',
71 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
72 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
78 __PACKAGE__->has_many(
79 cds_90s => 'DBICTest::Schema::CD',
83 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
84 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
91 __PACKAGE__->has_many(
92 cds_unordered => 'DBICTest::Schema::CD'
94 __PACKAGE__->has_many(
95 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
98 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
99 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
101 __PACKAGE__->has_many(
102 artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap',
103 [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ],
104 { cascade_copy => 0 } # this would *so* not make sense
107 __PACKAGE__->has_many(
108 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
110 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
113 sub sqlt_deploy_hook {
114 my ($self, $sqlt_table) = @_;
116 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
117 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
118 or die $sqlt_table->error;
123 my ($self, $name, $value) = @_;
124 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
125 $self->next::method($name, $value);