Most of the code reviewed... Missing ResultSet->populate, ResultSet->find, Row->copy...
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / Artist.pm
1 package # hide from PAUSE 
2     DBICTest::Schema::Artist;
3
4 use base qw/DBICTest::BaseResult/;
5
6 __PACKAGE__->table('artist');
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 });
12 __PACKAGE__->add_columns(
13   'artistid' => {
14     data_type => 'integer',
15     is_auto_increment => 1,
16   },
17   'name' => {
18     data_type => 'varchar',
19     size      => 100,
20     is_nullable => 1,
21   },
22   rank => {
23     data_type => 'integer',
24     default_value => 13,
25   },
26   charfield => {
27     data_type => 'char',
28     size => 10,
29     is_nullable => 1,
30   },
31 );
32 __PACKAGE__->set_primary_key('artistid');
33 __PACKAGE__->add_unique_constraint(['name']);
34 __PACKAGE__->add_unique_constraint(artist => ['artistid']); # do not remove, part of a test
35 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
36
37
38 __PACKAGE__->mk_classdata('field_name_for', {
39     artistid    => 'primary key',
40     name        => 'artist name',
41 });
42
43 __PACKAGE__->has_many(
44     cds => 'DBICTest::Schema::CD', undef,
45     { order_by => { -asc => 'year'} },
46 );
47
48
49 __PACKAGE__->has_many(
50     cds_80s => 'DBICTest::Schema::CD',
51     sub {
52       my ( $me_alias, $rel_alias, $me_result_source, $rel_name, $optional_me_object ) = @_;
53       return
54         ({ "${rel_alias}.artist"  => { '=' => \"${me_alias}.artistid"},
55            "${rel_alias}.year"    => { '>', "1979",
56                                        '<', "1990" }
57          },
58          $optional_me_object &&
59          { "${rel_alias}.artist" => $optional_me_object->artistid,
60            "${rel_alias}.year"   => { '>', "1979",
61                                       '<', "1990" }
62        });
63   }
64 );
65
66
67 __PACKAGE__->has_many(
68     cds_unordered => 'DBICTest::Schema::CD'
69 );
70 __PACKAGE__->has_many(
71     cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
72 );
73
74 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
75 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
76
77 __PACKAGE__->has_many(
78   artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap',
79   [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ],
80   { cascade_copy => 0 } # this would *so* not make sense
81 );
82
83 __PACKAGE__->has_many(
84     artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
85 );
86 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
87
88
89 sub sqlt_deploy_hook {
90   my ($self, $sqlt_table) = @_;
91
92   if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
93     $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
94       or die $sqlt_table->error;
95   }
96 }
97
98 sub store_column {
99   my ($self, $name, $value) = @_;
100   $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
101   $self->next::method($name, $value);
102 }
103
104
105 1;