[Dbix-class] breaking change ?
Peter Rabbitson
rabbit+dbic at rabbit.us
Mon Jun 22 10:36:53 GMT 2009
Gerrit Wichert wrote:
> 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) {
> ...
> }
>
Hmmm... this seems like a generalization of another regression that
currently lives in the unresolvable_prefetch/ branch, but nobody had
to look at it yet. Your example will be added as a test, and all of
this will hopefully be fixed in a week or two. Until then the only
solution is to explicitly select the PK.
More information about the DBIx-Class
mailing list