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