DBIx-Class-ParameterizedJoinHack

 view release on metacpan or  search on metacpan

t/00basic.t  view on Meta::CPAN

use strict;
use warnings;
use lib 't/lib';
use Test::More;
use Test::Fatal;
use My::Schema;

unless (eval { require DBD::SQLite; 1 }) {
    plan skip_all => 'Unable to load DBD::SQLite';
}

my $schema = My::Schema->connect('dbi:SQLite:dbname=:memory:');

$schema->deploy;

my $people = $schema->resultset('Person');

my $bob = $people->create({
    name => 'Bob Testuser',
});

$bob->create_related(assigned_tasks => {
    summary => 'Task A',
    urgency => 10,
});
$bob->create_related(assigned_tasks => {
    summary => 'Task B',
    urgency => 20,
});
$bob->create_related(assigned_tasks => {
    summary => 'Task C',
    urgency => 30,
});

subtest 'has_many' => sub {

    my $join_with_min = sub {
        return shift->with_parameterized_join(
            urgent_assigned_tasks => { urgency_threshold => $_[0] },
        );
    };

    my $join_with_range = sub {
        return shift->with_parameterized_join(
            tasks_in_urgency_range => {
                min => $_[0],
                max => $_[1],
            },
        );
    };

    my $search_count = sub {
        return scalar shift->search(
            { 'me.name' => { -like => 'Bob%' } },
            {
                '+select' => [{
                    count => \[shift],
                }],
                '+as' => ['task_count'],
            },
        );
    };
    my $search = sub { $search_count->(shift, 'urgent_assigned_tasks.id') };

    my $fetch_count = sub {



( run in 0.572 second using v1.01-cache-2.11-cpan-54e63673c56 )