Commit | Line | Data |
c6d74d3e |
1 | package # hide from PAUSE |
2 | DBICTest::Schema::Artist; |
a02675cd |
3 | |
660cf1be |
4 | use 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( |
50 | cds_80s => 'DBICTest::Schema::CD', |
51 | sub { |
cf320fd7 |
52 | my ( $me, $as, $self_rsrc, $rel ) = @_; |
53 | return { |
54 | "${as}.artist" => (ref $me ? $me->artistid : { '=' => \"${me}.artistid"}), |
55 | "${as}.year" => { '>', "1979", |
56 | '<', "1990" } |
57 | }; |
2255d0be |
58 | } |
59 | ); |
60 | |
61 | |
c193d1d2 |
62 | __PACKAGE__->has_many( |
63 | cds_unordered => 'DBICTest::Schema::CD' |
64 | ); |
62d4dbae |
65 | __PACKAGE__->has_many( |
66 | cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD' |
67 | ); |
ff657a43 |
68 | |
69 | __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' ); |
70 | __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' ); |
71 | |
72 | __PACKAGE__->has_many( |
73 | artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap', |
74 | [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ], |
75 | { cascade_copy => 0 } # this would *so* not make sense |
76 | ); |
77 | |
d5633096 |
78 | __PACKAGE__->has_many( |
04e0d6ef |
79 | artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id' |
d5633096 |
80 | ); |
04e0d6ef |
81 | __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork'); |
d5633096 |
82 | |
83 | |
aaf2403d |
84 | sub sqlt_deploy_hook { |
85 | my ($self, $sqlt_table) = @_; |
86 | |
d6c79cb3 |
87 | if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) { |
1f5bf324 |
88 | $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] ) |
d6c79cb3 |
89 | or die $sqlt_table->error; |
90 | } |
aaf2403d |
91 | } |
c385ecea |
92 | |
52c53388 |
93 | sub store_column { |
94 | my ($self, $name, $value) = @_; |
a22688ab |
95 | $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/); |
52c53388 |
96 | $self->next::method($name, $value); |
97 | } |
98 | |
99 | |
a02675cd |
100 | 1; |