Fix inexplicable 5.8.x C3 errors - roll back e6efde04
[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 'DBICTest::BaseResult';
8 use DBICTest::Util 'check_customcond_args';
9
10 # The component order is Part of a test,
11 # important to remain as-is
12 __PACKAGE__->load_components(qw{
13     +DBICTest::DeployComponent
14     InflateColumn::DateTime
15     Ordered
16 });
17
18 __PACKAGE__->table('track');
19 __PACKAGE__->add_columns(
20   'trackid' => {
21     data_type => 'integer',
22     is_auto_increment => 1,
23   },
24   'cd' => {
25     data_type => 'integer',
26   },
27   'position' => {
28     data_type => 'int',
29     accessor => 'pos',
30   },
31   'title' => {
32     data_type => 'varchar',
33     size      => 100,
34   },
35   last_updated_on => {
36     data_type => 'datetime',
37     accessor => 'updated_date',
38     is_nullable => 1
39   },
40   last_updated_at => {
41     data_type => 'datetime',
42     is_nullable => 1
43   },
44 );
45 __PACKAGE__->set_primary_key('trackid');
46
47 __PACKAGE__->add_unique_constraint([ qw/cd position/ ]);
48 __PACKAGE__->add_unique_constraint([ qw/cd title/ ]);
49
50 __PACKAGE__->position_column ('position');
51 __PACKAGE__->grouping_column ('cd');
52
53 # the undef condition in this rel is *deliberate*
54 # tests oddball legacy syntax
55 __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, {
56     proxy => { cd_title => 'title' },
57 });
58 # custom condition coderef
59 __PACKAGE__->belongs_to( cd_cref_cond => 'DBICTest::Schema::CD',
60 sub {
61   # This is for test purposes only. A regular user does not
62   # need to sanity check the passed-in arguments, this is what
63   # the tests are for :)
64   my $args = &check_customcond_args;
65
66   return (
67     {
68       "$args->{foreign_alias}.cdid" => { -ident => "$args->{self_alias}.cd" },
69     },
70
71     ! $args->{self_result_object} ? () : {
72      "$args->{foreign_alias}.cdid" => $args->{self_result_object}->get_column('cd')
73     },
74
75     ! $args->{foreign_values} ? () : {
76      "$args->{self_alias}.cd" => $args->{foreign_values}{cdid}
77     },
78   );
79 }
80 );
81 __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd', {
82     proxy => 'year'
83 });
84
85 __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' );
86 __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' );
87
88 __PACKAGE__->belongs_to(
89     "year1999cd",
90     "DBICTest::Schema::Year1999CDs",
91     'cd',
92     { join_type => 'left' },  # the relationship is of course optional
93 );
94 __PACKAGE__->belongs_to(
95     "year2000cd",
96     "DBICTest::Schema::Year2000CDs",
97     'cd',
98     { join_type => 'left' },
99 );
100
101 __PACKAGE__->has_many (
102   next_tracks => __PACKAGE__,
103   sub {
104     # This is for test purposes only. A regular user does not
105     # need to sanity check the passed-in arguments, this is what
106     # the tests are for :)
107     my $args = &check_customcond_args;
108
109     return (
110       { "$args->{foreign_alias}.cd"       => { -ident => "$args->{self_alias}.cd" },
111         "$args->{foreign_alias}.position" => { '>' => { -ident => "$args->{self_alias}.position" } },
112       },
113       $args->{self_result_object} && {
114         "$args->{foreign_alias}.cd"       => $args->{self_result_object}->get_column('cd'),
115         "$args->{foreign_alias}.position" => { '>' => $args->{self_result_object}->pos },
116       }
117     )
118   }
119 );
120
121 __PACKAGE__->has_many (
122   deliberately_broken_all_cd_tracks => __PACKAGE__,
123   sub {
124     # This is for test purposes only. A regular user does not
125     # need to sanity check the passed-in arguments, this is what
126     # the tests are for :)
127     my $args = &check_customcond_args;
128
129     return {
130       "$args->{foreign_alias}.cd" => "$args->{self_alias}.cd"
131     };
132   }
133 );
134
135 our $hook_cb;
136
137 sub sqlt_deploy_hook {
138   my $class = shift;
139
140   $hook_cb->($class, @_) if $hook_cb;
141   $class->next::method(@_) if $class->next::can;
142 }
143
144 1;