Add strict/warnings test, adjust all offenders (wow, that was a lot)
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / Track.pm
1 package # hide from PAUSE
2     DBICTest::Schema::Track;
3
4 use warnings;
5 use strict;
6
7 use base qw/DBICTest::BaseResult/;
8 use Carp qw/confess/;
9
10 __PACKAGE__->load_components(qw{
11     +DBICTest::DeployComponent
12     InflateColumn::DateTime
13     Ordered
14 });
15
16 __PACKAGE__->table('track');
17 __PACKAGE__->add_columns(
18   'trackid' => {
19     data_type => 'integer',
20     is_auto_increment => 1,
21   },
22   'cd' => {
23     data_type => 'integer',
24   },
25   'position' => {
26     data_type => 'int',
27     accessor => 'pos',
28   },
29   'title' => {
30     data_type => 'varchar',
31     size      => 100,
32   },
33   last_updated_on => {
34     data_type => 'datetime',
35     accessor => 'updated_date',
36     is_nullable => 1
37   },
38   last_updated_at => {
39     data_type => 'datetime',
40     is_nullable => 1
41   },
42 );
43 __PACKAGE__->set_primary_key('trackid');
44
45 __PACKAGE__->add_unique_constraint([ qw/cd position/ ]);
46 __PACKAGE__->add_unique_constraint([ qw/cd title/ ]);
47
48 __PACKAGE__->position_column ('position');
49 __PACKAGE__->grouping_column ('cd');
50
51
52 __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, {
53     proxy => { cd_title => 'title' },
54 });
55 __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd', {
56     proxy => 'year'
57 });
58
59 __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' );
60 __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' );
61
62 __PACKAGE__->belongs_to(
63     "year1999cd",
64     "DBICTest::Schema::Year1999CDs",
65     { "foreign.cdid" => "self.cd" },
66     { join_type => 'left' },  # the relationship is of course optional
67 );
68 __PACKAGE__->belongs_to(
69     "year2000cd",
70     "DBICTest::Schema::Year2000CDs",
71     { "foreign.cdid" => "self.cd" },
72     { join_type => 'left' },
73 );
74
75 __PACKAGE__->has_many (
76   next_tracks => __PACKAGE__,
77   sub {
78     my $args = shift;
79
80     # This is for test purposes only. A regular user does not
81     # need to sanity check the passed-in arguments, this is what
82     # the tests are for :)
83     my @missing_args = grep { ! defined $args->{$_} }
84       qw/self_alias foreign_alias self_resultsource foreign_relname/;
85     confess "Required arguments not supplied to custom rel coderef: @missing_args\n"
86       if @missing_args;
87
88     return (
89       { "$args->{foreign_alias}.cd"       => { -ident => "$args->{self_alias}.cd" },
90         "$args->{foreign_alias}.position" => { '>' => { -ident => "$args->{self_alias}.position" } },
91       },
92       $args->{self_rowobj} && {
93         "$args->{foreign_alias}.cd"       => $args->{self_rowobj}->get_column('cd'),
94         "$args->{foreign_alias}.position" => { '>' => $args->{self_rowobj}->pos },
95       }
96     )
97   }
98 );
99
100 our $hook_cb;
101
102 sub sqlt_deploy_hook {
103   my $class = shift;
104
105   $hook_cb->($class, @_) if $hook_cb;
106   $class->next::method(@_) if $class->next::can;
107 }
108
109 1;