Switch code/documentation/examples/tests to the new single-arg syntax
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / Track.pm
1 package # hide from PAUSE
2     DBICTest::Schema::Track;
3
4 use base qw/DBICTest::BaseResult/;
5 __PACKAGE__->load_components(qw/InflateColumn::DateTime Ordered/);
6
7 __PACKAGE__->table('track');
8 __PACKAGE__->add_columns(
9   'trackid' => {
10     data_type => 'integer',
11     is_auto_increment => 1,
12   },
13   'cd' => {
14     data_type => 'integer',
15   },
16   'position' => {
17     data_type => 'int',
18     accessor => 'pos',
19   },
20   'title' => {
21     data_type => 'varchar',
22     size      => 100,
23   },
24   last_updated_on => {
25     data_type => 'datetime',
26     accessor => 'updated_date',
27     is_nullable => 1
28   },
29   last_updated_at => {
30     data_type => 'datetime',
31     is_nullable => 1
32   },
33 );
34 __PACKAGE__->set_primary_key('trackid');
35
36 __PACKAGE__->add_unique_constraint([ qw/cd position/ ]);
37 __PACKAGE__->add_unique_constraint([ qw/cd title/ ]);
38
39 __PACKAGE__->position_column ('position');
40 __PACKAGE__->grouping_column ('cd');
41
42
43 __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, {
44     proxy => { cd_title => 'title' },
45 });
46 __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd', {
47     proxy => 'year'
48 });
49
50 __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' );
51 __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' );
52
53 __PACKAGE__->belongs_to(
54     "year1999cd",
55     "DBICTest::Schema::Year1999CDs",
56     { "foreign.cdid" => "self.cd" },
57     { join_type => 'left' },  # the relationship is of course optional
58 );
59 __PACKAGE__->belongs_to(
60     "year2000cd",
61     "DBICTest::Schema::Year2000CDs",
62     { "foreign.cdid" => "self.cd" },
63     { join_type => 'left' },
64 );
65
66 __PACKAGE__->might_have (
67   next_track => __PACKAGE__,
68   sub {
69     my $args = shift;
70     return (
71       { "$args->{foreign_alias}.cd"       => { -ident => "$args->{self_alias}.cd" },
72         "$args->{foreign_alias}.position" => { '>' => { -ident => "$args->{self_alias}.position" } },
73       },
74       $args->{self_rowobj} && {
75         "$args->{foreign_alias}.cd"       => $args->{self_rowobj}->cd,
76         "$args->{foreign_alias}.position" => { '>' => $args->{self_rowobj}->position },
77       }
78     )
79   }
80 );
81
82 1;