[Dbix-class] breaking change ?

Gerrit Wichert gw at green-stores.de
Mon Jun 22 10:23:50 GMT 2009


hello,

im using the following code  for quite some time (about a year) to get
values of two related rows of the same table.
This worked very well. But since the last upgrade of DBIx:_Class to
version 0.08107 it failed with the following error:

DBIx::Class::ResultSet::next(): Column id not loaded or not passed to
new() prior to insert() on
GS::Model::TimeControl::DBIx::TimeSheet=HASH(0x9707b0c) trying to
resolve relationship (maybe you forgot to call ->discard_changes to get
defaults from the db) at ...

changing the select from:
   select => [ qw/ me.login me.host me.type me.mtime end.mtime /],
to
   select => [ qw/ me.login me.host me.type me.mtime end.mtime me.id/],
makes it work again.
So is seems to fail when not including the primary key into the result.

Is this really necessary to select the primary key?
Is it a bug or a breaking change or can i write such requests in a
better way?


And btw. did anyone know of a db-portable way to deflate DateTime values
in where statements?

thanks,
  Gerrit Wichert





package GS::DBIC::Schemata::TimeControl::TimeSheet;

use strict;
use warnings;

use base qw/DBIx::Class/;

__PACKAGE__->load_components(qw/ InflateColumn::DateTime Core /);
__PACKAGE__->table('time');
__PACKAGE__->add_columns( qw/ id login type pid host /);
__PACKAGE__->add_columns(  mtime =>{data_type =>'TIMESTAMP'},);
__PACKAGE__->set_primary_key('id');

__PACKAGE__->belongs_to(
    'end',
    __PACKAGE__,
    {'foreign.pid'=>'self.id'},
    {'join_type' => 'left'}
    );
1;



...
my $rs = $schema->resultset('TimeSheet')->
          search( {'me.login' => $employeeId,
                         'me.pid'   => {'=' => 0},
                         'me.mtime' => {
                                                    '>'  => $date->ymd,
                                                    '<'  =>
$date->clone->add(days=>1)->ymd
                                                   }
                        },
                        { join   => [qw/ end /],        
                          select => [ qw/ me.login me.host me.type
me.mtime end.mtime /],
                        });

while (my $entry = $rs->next) {
...
}  





More information about the DBIx-Class mailing list