Commit | Line | Data |
8273e845 |
1 | package # hide from PAUSE |
c6d74d3e |
2 | DBICTest::Schema::Artist; |
a02675cd |
3 | |
4a233f30 |
4 | use warnings; |
5 | use strict; |
6 | |
660cf1be |
7 | use base qw/DBICTest::BaseResult/; |
6fbef4a4 |
8 | use 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 | |
98fcc1c0 |
47 | # the undef condition in this rel is *deliberate* |
48 | # tests oddball legacy syntax |
ff657a43 |
49 | __PACKAGE__->has_many( |
50 | cds => 'DBICTest::Schema::CD', undef, |
d2fcb9b3 |
51 | { order_by => { -asc => 'year'} }, |
ff657a43 |
52 | ); |
2255d0be |
53 | |
54 | |
55 | __PACKAGE__->has_many( |
6c4f4d69 |
56 | cds_80s => 'DBICTest::Schema::CD', |
57 | sub { |
58 | my $args = shift; |
59 | |
6fbef4a4 |
60 | # This is for test purposes only. A regular user does not |
61 | # need to sanity check the passed-in arguments, this is what |
62 | # the tests are for :) |
63 | my @missing_args = grep { ! defined $args->{$_} } |
64 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
65 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
66 | if @missing_args; |
67 | |
6c4f4d69 |
68 | return ( |
69 | { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} }, |
70 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
71 | }, |
72 | $args->{self_rowobj} && { |
73 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
74 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
75 | } |
76 | ); |
77 | }, |
2255d0be |
78 | ); |
79 | |
abf8d91e |
80 | |
9aae3566 |
81 | __PACKAGE__->has_many( |
abf8d91e |
82 | cds_84 => 'DBICTest::Schema::CD', |
6c4f4d69 |
83 | sub { |
84 | my $args = shift; |
6fbef4a4 |
85 | |
86 | # This is for test purposes only. A regular user does not |
87 | # need to sanity check the passed-in arguments, this is what |
88 | # the tests are for :) |
89 | my @missing_args = grep { ! defined $args->{$_} } |
90 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
91 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
92 | if @missing_args; |
93 | |
6c4f4d69 |
94 | return ( |
95 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
96 | "$args->{foreign_alias}.year" => 1984, |
97 | }, |
98 | $args->{self_rowobj} && { |
99 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
100 | "$args->{foreign_alias}.year" => 1984, |
6c4f4d69 |
101 | } |
102 | ); |
d5a14c53 |
103 | } |
9aae3566 |
104 | ); |
105 | |
d5a14c53 |
106 | |
9aae3566 |
107 | __PACKAGE__->has_many( |
abf8d91e |
108 | cds_90s => 'DBICTest::Schema::CD', |
6c4f4d69 |
109 | sub { |
110 | my $args = shift; |
6fbef4a4 |
111 | |
112 | # This is for test purposes only. A regular user does not |
113 | # need to sanity check the passed-in arguments, this is what |
114 | # the tests are for :) |
115 | my @missing_args = grep { ! defined $args->{$_} } |
116 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
117 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
118 | if @missing_args; |
119 | |
6c4f4d69 |
120 | return ( |
121 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
122 | "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 }, |
6c4f4d69 |
123 | } |
124 | ); |
9aae3566 |
125 | } |
126 | ); |
127 | |
2255d0be |
128 | |
c193d1d2 |
129 | __PACKAGE__->has_many( |
130 | cds_unordered => 'DBICTest::Schema::CD' |
131 | ); |
62d4dbae |
132 | __PACKAGE__->has_many( |
133 | cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD' |
134 | ); |
ff657a43 |
135 | |
136 | __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' ); |
137 | __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' ); |
138 | |
139 | __PACKAGE__->has_many( |
140 | artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap', |
141 | [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ], |
142 | { cascade_copy => 0 } # this would *so* not make sense |
143 | ); |
144 | |
d5633096 |
145 | __PACKAGE__->has_many( |
04e0d6ef |
146 | artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id' |
d5633096 |
147 | ); |
04e0d6ef |
148 | __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork'); |
d5633096 |
149 | |
150 | |
aaf2403d |
151 | sub sqlt_deploy_hook { |
152 | my ($self, $sqlt_table) = @_; |
153 | |
d6c79cb3 |
154 | if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) { |
1f5bf324 |
155 | $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] ) |
d6c79cb3 |
156 | or die $sqlt_table->error; |
157 | } |
aaf2403d |
158 | } |
c385ecea |
159 | |
52c53388 |
160 | sub store_column { |
161 | my ($self, $name, $value) = @_; |
a22688ab |
162 | $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/); |
52c53388 |
163 | $self->next::method($name, $value); |
164 | } |
165 | |
166 | |
a02675cd |
167 | 1; |