Add strict/warnings test, adjust all offenders (wow, that was a lot)
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / Artist.pm
CommitLineData
8273e845 1package # hide from PAUSE
c6d74d3e 2 DBICTest::Schema::Artist;
a02675cd 3
4a233f30 4use warnings;
5use strict;
6
660cf1be 7use base qw/DBICTest::BaseResult/;
6fbef4a4 8use Carp qw/confess/;
a02675cd 9
ff657a43 10__PACKAGE__->table('artist');
a48e92d7 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",
15});
ff657a43 16__PACKAGE__->add_columns(
0009fa49 17 'artistid' => {
18 data_type => 'integer',
6e399b4f 19 is_auto_increment => 1,
0009fa49 20 },
21 'name' => {
22 data_type => 'varchar',
cb561d1a 23 size => 100,
0009fa49 24 is_nullable => 1,
25 },
39da2a2b 26 rank => {
27 data_type => 'integer',
28 default_value => 13,
29 },
a0dd8679 30 charfield => {
31 data_type => 'char',
32 size => 10,
33 is_nullable => 1,
34 },
0009fa49 35);
ff657a43 36__PACKAGE__->set_primary_key('artistid');
84f7e8a1 37__PACKAGE__->add_unique_constraint(['name']);
1a625304 38__PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
e29e2b27 39__PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
a02675cd 40
84f7e8a1 41
90e6de6c 42__PACKAGE__->mk_classdata('field_name_for', {
43 artistid => 'primary key',
44 name => 'artist name',
45});
46
ff657a43 47__PACKAGE__->has_many(
48 cds => 'DBICTest::Schema::CD', undef,
d2fcb9b3 49 { order_by => { -asc => 'year'} },
ff657a43 50);
2255d0be 51
52
53__PACKAGE__->has_many(
6c4f4d69 54 cds_80s => 'DBICTest::Schema::CD',
55 sub {
56 my $args = shift;
57
6fbef4a4 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"
64 if @missing_args;
65
6c4f4d69 66 return (
67 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
68 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
69 },
70 $args->{self_rowobj} && {
71 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
72 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
73 }
74 );
75 },
2255d0be 76);
77
abf8d91e 78
9aae3566 79__PACKAGE__->has_many(
abf8d91e 80 cds_84 => 'DBICTest::Schema::CD',
6c4f4d69 81 sub {
82 my $args = shift;
6fbef4a4 83
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"
90 if @missing_args;
91
6c4f4d69 92 return (
93 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
abf8d91e 94 "$args->{foreign_alias}.year" => 1984,
95 },
96 $args->{self_rowobj} && {
97 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
98 "$args->{foreign_alias}.year" => 1984,
6c4f4d69 99 }
100 );
d5a14c53 101 }
9aae3566 102);
103
d5a14c53 104
9aae3566 105__PACKAGE__->has_many(
abf8d91e 106 cds_90s => 'DBICTest::Schema::CD',
6c4f4d69 107 sub {
108 my $args = shift;
6fbef4a4 109
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"
116 if @missing_args;
117
6c4f4d69 118 return (
119 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
abf8d91e 120 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
6c4f4d69 121 }
122 );
9aae3566 123 }
124);
125
2255d0be 126
c193d1d2 127__PACKAGE__->has_many(
128 cds_unordered => 'DBICTest::Schema::CD'
129);
62d4dbae 130__PACKAGE__->has_many(
131 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
132);
ff657a43 133
134__PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
135__PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
136
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
141);
142
d5633096 143__PACKAGE__->has_many(
04e0d6ef 144 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
d5633096 145);
04e0d6ef 146__PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
d5633096 147
148
aaf2403d 149sub sqlt_deploy_hook {
150 my ($self, $sqlt_table) = @_;
151
d6c79cb3 152 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
1f5bf324 153 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
d6c79cb3 154 or die $sqlt_table->error;
155 }
aaf2403d 156}
c385ecea 157
52c53388 158sub store_column {
159 my ($self, $name, $value) = @_;
a22688ab 160 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
52c53388 161 $self->next::method($name, $value);
162}
163
164
a02675cd 1651;