[Dbix-class] "Having" problems

Jonathan Rockway jon at jrock.us
Sun Apr 20 10:24:38 BST 2008


It seems that having (heh) a "having" clause breaks row inflation.  Here
is a test case:

    use strict;
    
    package Schema::Foo;
    use base 'DBIx::Class';
        
    __PACKAGE__->load_components(qw/Core/);
    __PACKAGE__->table('foos');
    __PACKAGE__->add_columns(
        foos => {
            data_type         => 'INTEGER',
            is_nullable       => 0,
        },
    );
    __PACKAGE__->set_primary_key('foos');
        
    package Schema;
    use base 'DBIx::Class::Schema';
    __PACKAGE__->load_classes('Foo');
    
    use Test::More tests => 3;
    use DBICx::TestDatabase;
    
    $INC{'Schema.pm'} = 1;
        
    my $s = DBICx::TestDatabase->new('Schema');
    ok $s, 'got db';
    
    $s->resultset('Foo')->create({ foos => 42 });
    
    my $rs = $s->resultset('Foo')->search({}, { 
        having   => { 1 => 1 }, # comment this out to make the tests pass
        group_by => '1',
    });
    
    is $rs->count, 1, '1 result';
    ok $rs->first, 'got a first result';

Basically if you comment out the having line, the tests pass.  Without
it, the count is correct, but $rs->first, $rs->next, $rs->all,
etc. return undef (even though the query would generate rows).  I've
tried this with a more complex query, and it works fine[1] without
having, but with the having clause, it returns the correct count but
undef for first/next/all/etc.  The problem also happens if I use a
different result class, like HashRefInflator.

[1] Well, without "having", the results are obviously wrong.  But DBIC
works correctly :)

Just for reference, running the DBIC_TRACE'd query in dbish or whatever
returns the correct results for both fetching rows and counting them.
So DBIC is generating and running the correct query, but it's just not
inflating the results.

Anyway, very odd.

Regards,
Jonathan Rockway

-- 
print just => another => perl => hacker => if $,=$"



More information about the DBIx-Class mailing list