Commit | Line | Data |
c6d74d3e |
1 | package # hide from PAUSE |
2 | DBICTest::Schema::Artist; |
a02675cd |
3 | |
660cf1be |
4 | use base qw/DBICTest::BaseResult/; |
6fbef4a4 |
5 | use Carp qw/confess/; |
a02675cd |
6 | |
ff657a43 |
7 | __PACKAGE__->table('artist'); |
a48e92d7 |
8 | __PACKAGE__->source_info({ |
9 | "source_info_key_A" => "source_info_value_A", |
10 | "source_info_key_B" => "source_info_value_B", |
11 | "source_info_key_C" => "source_info_value_C", |
12 | }); |
ff657a43 |
13 | __PACKAGE__->add_columns( |
0009fa49 |
14 | 'artistid' => { |
15 | data_type => 'integer', |
6e399b4f |
16 | is_auto_increment => 1, |
0009fa49 |
17 | }, |
18 | 'name' => { |
19 | data_type => 'varchar', |
cb561d1a |
20 | size => 100, |
0009fa49 |
21 | is_nullable => 1, |
22 | }, |
39da2a2b |
23 | rank => { |
24 | data_type => 'integer', |
25 | default_value => 13, |
26 | }, |
a0dd8679 |
27 | charfield => { |
28 | data_type => 'char', |
29 | size => 10, |
30 | is_nullable => 1, |
31 | }, |
0009fa49 |
32 | ); |
ff657a43 |
33 | __PACKAGE__->set_primary_key('artistid'); |
84f7e8a1 |
34 | __PACKAGE__->add_unique_constraint(['name']); |
1a625304 |
35 | __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test |
e29e2b27 |
36 | __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]); |
a02675cd |
37 | |
84f7e8a1 |
38 | |
90e6de6c |
39 | __PACKAGE__->mk_classdata('field_name_for', { |
40 | artistid => 'primary key', |
41 | name => 'artist name', |
42 | }); |
43 | |
ff657a43 |
44 | __PACKAGE__->has_many( |
45 | cds => 'DBICTest::Schema::CD', undef, |
d2fcb9b3 |
46 | { order_by => { -asc => 'year'} }, |
ff657a43 |
47 | ); |
2255d0be |
48 | |
49 | |
50 | __PACKAGE__->has_many( |
6c4f4d69 |
51 | cds_80s => 'DBICTest::Schema::CD', |
52 | sub { |
53 | my $args = shift; |
54 | |
6fbef4a4 |
55 | # This is for test purposes only. A regular user does not |
56 | # need to sanity check the passed-in arguments, this is what |
57 | # the tests are for :) |
58 | my @missing_args = grep { ! defined $args->{$_} } |
59 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
60 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
61 | if @missing_args; |
62 | |
6c4f4d69 |
63 | return ( |
64 | { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} }, |
65 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
66 | }, |
67 | $args->{self_rowobj} && { |
68 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
69 | "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, |
70 | } |
71 | ); |
72 | }, |
2255d0be |
73 | ); |
74 | |
abf8d91e |
75 | |
9aae3566 |
76 | __PACKAGE__->has_many( |
abf8d91e |
77 | cds_84 => 'DBICTest::Schema::CD', |
6c4f4d69 |
78 | sub { |
79 | my $args = shift; |
6fbef4a4 |
80 | |
81 | # This is for test purposes only. A regular user does not |
82 | # need to sanity check the passed-in arguments, this is what |
83 | # the tests are for :) |
84 | my @missing_args = grep { ! defined $args->{$_} } |
85 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
86 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
87 | if @missing_args; |
88 | |
6c4f4d69 |
89 | return ( |
90 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
91 | "$args->{foreign_alias}.year" => 1984, |
92 | }, |
93 | $args->{self_rowobj} && { |
94 | "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, |
95 | "$args->{foreign_alias}.year" => 1984, |
6c4f4d69 |
96 | } |
97 | ); |
d5a14c53 |
98 | } |
9aae3566 |
99 | ); |
100 | |
d5a14c53 |
101 | |
9aae3566 |
102 | __PACKAGE__->has_many( |
abf8d91e |
103 | cds_90s => 'DBICTest::Schema::CD', |
6c4f4d69 |
104 | sub { |
105 | my $args = shift; |
6fbef4a4 |
106 | |
107 | # This is for test purposes only. A regular user does not |
108 | # need to sanity check the passed-in arguments, this is what |
109 | # the tests are for :) |
110 | my @missing_args = grep { ! defined $args->{$_} } |
111 | qw/self_alias foreign_alias self_resultsource foreign_relname/; |
112 | confess "Required arguments not supplied to custom rel coderef: @missing_args\n" |
113 | if @missing_args; |
114 | |
6c4f4d69 |
115 | return ( |
116 | { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, |
abf8d91e |
117 | "$args->{foreign_alias}.year" => { '>' => 1989, '<' => 2000 }, |
6c4f4d69 |
118 | } |
119 | ); |
9aae3566 |
120 | } |
121 | ); |
122 | |
2255d0be |
123 | |
c193d1d2 |
124 | __PACKAGE__->has_many( |
125 | cds_unordered => 'DBICTest::Schema::CD' |
126 | ); |
62d4dbae |
127 | __PACKAGE__->has_many( |
128 | cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD' |
129 | ); |
ff657a43 |
130 | |
131 | __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' ); |
132 | __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' ); |
133 | |
134 | __PACKAGE__->has_many( |
135 | artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap', |
136 | [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ], |
137 | { cascade_copy => 0 } # this would *so* not make sense |
138 | ); |
139 | |
d5633096 |
140 | __PACKAGE__->has_many( |
04e0d6ef |
141 | artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id' |
d5633096 |
142 | ); |
04e0d6ef |
143 | __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork'); |
d5633096 |
144 | |
145 | |
aaf2403d |
146 | sub sqlt_deploy_hook { |
147 | my ($self, $sqlt_table) = @_; |
148 | |
d6c79cb3 |
149 | if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) { |
1f5bf324 |
150 | $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] ) |
d6c79cb3 |
151 | or die $sqlt_table->error; |
152 | } |
aaf2403d |
153 | } |
c385ecea |
154 | |
52c53388 |
155 | sub store_column { |
156 | my ($self, $name, $value) = @_; |
a22688ab |
157 | $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/); |
52c53388 |
158 | $self->next::method($name, $value); |
159 | } |
160 | |
161 | |
a02675cd |
162 | 1; |