Add strict/warnings test, adjust all offenders (wow, that was a lot)
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / Artist.pm
1 package # hide from PAUSE
2     DBICTest::Schema::Artist;
3
4 use warnings;
5 use strict;
6
7 use base qw/DBICTest::BaseResult/;
8 use Carp qw/confess/;
9
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",
15 });
16 __PACKAGE__->add_columns(
17   'artistid' => {
18     data_type => 'integer',
19     is_auto_increment => 1,
20   },
21   'name' => {
22     data_type => 'varchar',
23     size      => 100,
24     is_nullable => 1,
25   },
26   rank => {
27     data_type => 'integer',
28     default_value => 13,
29   },
30   charfield => {
31     data_type => 'char',
32     size => 10,
33     is_nullable => 1,
34   },
35 );
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/]);
40
41
42 __PACKAGE__->mk_classdata('field_name_for', {
43     artistid    => 'primary key',
44     name        => 'artist name',
45 });
46
47 __PACKAGE__->has_many(
48     cds => 'DBICTest::Schema::CD', undef,
49     { order_by => { -asc => 'year'} },
50 );
51
52
53 __PACKAGE__->has_many(
54   cds_80s => 'DBICTest::Schema::CD',
55   sub {
56     my $args = shift;
57
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
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   },
76 );
77
78
79 __PACKAGE__->has_many(
80   cds_84 => 'DBICTest::Schema::CD',
81   sub {
82     my $args = shift;
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
92     return (
93       { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
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,
99       }
100     );
101   }
102 );
103
104
105 __PACKAGE__->has_many(
106   cds_90s => 'DBICTest::Schema::CD',
107   sub {
108     my $args = shift;
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
118     return (
119       { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
120         "$args->{foreign_alias}.year"   => { '>' => 1989, '<' => 2000 },
121       }
122     );
123   }
124 );
125
126
127 __PACKAGE__->has_many(
128     cds_unordered => 'DBICTest::Schema::CD'
129 );
130 __PACKAGE__->has_many(
131     cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
132 );
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
143 __PACKAGE__->has_many(
144     artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
145 );
146 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
147
148
149 sub sqlt_deploy_hook {
150   my ($self, $sqlt_table) = @_;
151
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;
155   }
156 }
157
158 sub store_column {
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);
162 }
163
164
165 1;