Switch code/documentation/examples/tests to the new single-arg syntax
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / Artist.pm
CommitLineData
c6d74d3e 1package # hide from PAUSE
2 DBICTest::Schema::Artist;
a02675cd 3
660cf1be 4use base qw/DBICTest::BaseResult/;
a02675cd 5
ff657a43 6__PACKAGE__->table('artist');
a48e92d7 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",
11});
ff657a43 12__PACKAGE__->add_columns(
0009fa49 13 'artistid' => {
14 data_type => 'integer',
6e399b4f 15 is_auto_increment => 1,
0009fa49 16 },
17 'name' => {
18 data_type => 'varchar',
cb561d1a 19 size => 100,
0009fa49 20 is_nullable => 1,
21 },
39da2a2b 22 rank => {
23 data_type => 'integer',
24 default_value => 13,
25 },
a0dd8679 26 charfield => {
27 data_type => 'char',
28 size => 10,
29 is_nullable => 1,
30 },
0009fa49 31);
ff657a43 32__PACKAGE__->set_primary_key('artistid');
84f7e8a1 33__PACKAGE__->add_unique_constraint(['name']);
1a625304 34__PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
e29e2b27 35__PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
a02675cd 36
84f7e8a1 37
90e6de6c 38__PACKAGE__->mk_classdata('field_name_for', {
39 artistid => 'primary key',
40 name => 'artist name',
41});
42
ff657a43 43__PACKAGE__->has_many(
44 cds => 'DBICTest::Schema::CD', undef,
d2fcb9b3 45 { order_by => { -asc => 'year'} },
ff657a43 46);
2255d0be 47
48
49__PACKAGE__->has_many(
6c4f4d69 50 cds_80s => 'DBICTest::Schema::CD',
51 sub {
52 my $args = shift;
53
54 return (
55 { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} },
56 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
57 },
58 $args->{self_rowobj} && {
59 "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid,
60 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
61 }
62 );
63 },
2255d0be 64);
65
9aae3566 66__PACKAGE__->has_many(
6c4f4d69 67 cds_80s_noopt => 'DBICTest::Schema::CD',
68 sub {
69 my $args = shift;
70 return (
71 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
72 "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 },
73 }
74 );
75 },
9aae3566 76);
77
78__PACKAGE__->has_many(
6c4f4d69 79 cds_90s => 'DBICTest::Schema::CD',
80 sub {
81 my $args = shift;
82 return (
83 { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
84 "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 },
85 }
86 );
9aae3566 87 }
88);
89
2255d0be 90
c193d1d2 91__PACKAGE__->has_many(
92 cds_unordered => 'DBICTest::Schema::CD'
93);
62d4dbae 94__PACKAGE__->has_many(
95 cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
96);
ff657a43 97
98__PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
99__PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
100
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
105);
106
d5633096 107__PACKAGE__->has_many(
04e0d6ef 108 artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
d5633096 109);
04e0d6ef 110__PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
d5633096 111
112
aaf2403d 113sub sqlt_deploy_hook {
114 my ($self, $sqlt_table) = @_;
115
d6c79cb3 116 if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
1f5bf324 117 $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
d6c79cb3 118 or die $sqlt_table->error;
119 }
aaf2403d 120}
c385ecea 121
52c53388 122sub store_column {
123 my ($self, $name, $value) = @_;
a22688ab 124 $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
52c53388 125 $self->next::method($name, $value);
126}
127
128
a02675cd 1291;