7 my $schema = My::Schema->connect('dbi:SQLite:dbname=:memory:');
11 my $people = $schema->resultset('Person');
13 my $bob = $people->create({
14 name => 'Bob Testuser',
17 $bob->create_related(assigned_tasks => {
21 $bob->create_related(assigned_tasks => {
25 $bob->create_related(assigned_tasks => {
30 subtest 'has_many' => sub {
32 my $join_with_min = sub {
33 return shift->with_parameterized_join(
34 urgent_assigned_tasks => { urgency_threshold => $_[0] },
38 # my $join_with_range = sub {
39 # return shift->with_parameterized_join(
40 # tasks_in_urgency_range => {
48 return scalar shift->search(
49 { 'me.name' => { -like => 'Bob%' } },
52 count => \['urgent_assigned_tasks.id'],
54 '+as' => ['task_count'],
59 my $fetch_count = sub {
60 return shift->next->get_column('task_count');
63 subtest 'simple filter' => sub {
64 is $people->$join_with_min(19)->$search->$fetch_count,
66 is $people->$join_with_min(29)->$search->$fetch_count,
68 is $people->$join_with_min(39)->$search->$fetch_count,
72 subtest 'multiple filters' => sub {
73 my $rs1 = $people->$join_with_min(19)->$search;
74 my $rs2 = $people->$join_with_min(29)->$search;
75 is $rs1->$fetch_count, 2, 'first';
76 is $rs2->$fetch_count, 1, 'second';
79 subtest 'overrides' => sub {
85 2, 'overridden parameter';
88 # subtest 'multi parameter' => sub {
89 # is $people->$join_with_range(10, 30)->$search->$fetch_count,