rework the local-izing code to navigate the maze of references correctly
[dbsrgits/DBIx-Class-ParameterizedJoinHack.git] / t / lib / My / Schema / Result / Person.pm
CommitLineData
638c1533 1package My::Schema::Result::Person;
2
3use strict;
4use warnings;
5use base qw(DBIx::Class::Core);
6
7__PACKAGE__->load_components(qw(ParameterizedJoinHack));
8
9__PACKAGE__->table('people');
10
11__PACKAGE__->add_columns(
12 id => { data_type => 'integer', is_nullable => 0, is_auto_increment => 1 },
13 name => { data_type => 'text', is_nullable => 0 }
14);
15
16__PACKAGE__->set_primary_key('id');
17
18__PACKAGE__->has_many(
19 assigned_tasks => 'My::Schema::Result::Task',
20 { 'foreign.assigned_to_id' => 'self.id' },
21);
22
23__PACKAGE__->parameterized_has_many(
24 urgent_assigned_tasks => 'My::Schema::Result::Task',
25 [ [ qw(urgency_threshold) ], sub {
26 my $args = shift;
27 +{
28 "$args->{foreign_alias}.assigned_to_id" =>
29 { -ident => "$args->{self_alias}.id" },
30 "$args->{foreign_alias}.urgency" =>
31 { '>', $_{urgency_threshold} }
32 }
33 }
34 ]
35);
36
ddc15dd9 37__PACKAGE__->parameterized_has_many(
38 tasks_in_urgency_range => 'My::Schema::Result::Task',
39 [ [ qw( min max ) ], sub {
40 my $args = shift;
41 +{
42 "$args->{foreign_alias}.assigned_to_id" =>
43 { -ident => "$args->{self_alias}.id" },
44 "$args->{foreign_alias}.urgency" =>
45 { '>=', $_{min} },
46 "$args->{foreign_alias}.urgency" =>
47 { '<=', $_{max} },
48 }
49 }
50 ]
51);
52
638c1533 531;