[Dbix-class] Maybe a Regression? Without a primary key,
prefetches fail.
J. Shirley
jshirley at gmail.com
Wed Mar 24 00:08:41 GMT 2010
I'm not sure if this counts as a regression, but it was for me :)
I have a class which is defined as:
package MyApp::Schema::StupidJoinTable;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("stupid_join_table");
__PACKAGE__->add_columns(
"stupid_id",
{
data_type => "integer",
default_value => undef,
is_nullable => 0,
size => 11
},
"stupider_id",
{
data_type => "integer",
default_value => undef,
is_nullable => 0,
size => 11
},
);
__PACKAGE__->belongs_to( 'thing_1', 'MyApp::Schema::Thing', 'stupid_id');
__PACKAGE__->belongs_to( 'thing_2', 'MyApp::Schema::Thing2', 'stupider_id');
1;
Now, if I attempt to prefetch this relationship, I get this error
thrown (from DBIx/Class/Row.pm, line 1138):
$class->throw_exception("Implicit prefetch (via select/columns)
not supported with accessor 'multi'");
The reason is that without ->set_primary_key(...) in this result
definition, the query on type is an empty array.
So, $prefetch->{$pre} is simply an empty array (the line "if (ref
$prefetch->{$pre}[0] eq 'ARRAY')").
This behavior is not changed if I explicitly define the columns on the
relationships (eg., { 'foreign.stupid_id' => 'self.stupid_id' })
I'm still running 0.08115 in production, so it is working there, but
this came up on my tests as a failure. The fix for me is just adding
in the primary keys as they should be, but it seemed like an odd
behavior.
If it's a bug, I'm happy to at least commit a failing test case :)
Thanks,
-Jay
More information about the DBIx-Class
mailing list