Fix spotty handling of complex order_by relationship attrs while prefetching
[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(artist => ['artistid']); # do not remove, part of a test
34
35 __PACKAGE__->mk_classdata('field_name_for', {
36     artistid    => 'primary key',
37     name        => 'artist name',
38 });
39
40 __PACKAGE__->has_many(
41     cds => 'DBICTest::Schema::CD', undef,
42     { order_by => { -asc => 'year'} },
43 );
44 __PACKAGE__->has_many(
45     cds_unordered => 'DBICTest::Schema::CD'
46 );
47 __PACKAGE__->has_many(
48     cds_very_very_very_long_relationship_name => 'DBICTest::Schema::CD'
49 );
50
51 __PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
52 __PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
53
54 __PACKAGE__->has_many(
55   artist_undirected_maps => 'DBICTest::Schema::ArtistUndirectedMap',
56   [ {'foreign.id1' => 'self.artistid'}, {'foreign.id2' => 'self.artistid'} ],
57   { cascade_copy => 0 } # this would *so* not make sense
58 );
59
60 __PACKAGE__->has_many(
61     artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
62 );
63 __PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');
64
65
66 sub sqlt_deploy_hook {
67   my ($self, $sqlt_table) = @_;
68
69   if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
70     $sqlt_table->add_index( name => 'artist_name_hookidx', fields => ['name'] )
71       or die $sqlt_table->error;
72   }
73 }
74
75 sub store_column {
76   my ($self, $name, $value) = @_;
77   $value = 'X '.$value if ($name eq 'name' && $value && $value =~ /(X )?store_column test/);
78   $self->next::method($name, $value);
79 }
80
81
82 1;