[Dbix-class] columns/join versus prefetch issue

Marc Logghe Marc.Logghe at DEVGEN.com
Thu Sep 28 12:57:34 CEST 2006


Hi all,
I am pretty new to DBIC, and currently I am still getting acquainted
with the interface.
Consider the following relationships (apologies for the long post but I
wanted to share as much info as possible):
in PoseDB::CompCorp:
__PACKAGE__->has_many(
  "poses",
  "PsdbPose",
  { "foreign.molid" => "self.compound_id" }, );

in PoseDB::PsdbModel:
__PACKAGE__->has_many(
  "poses",
  "PsdbPose",
  { "foreign.modelid" => "self.modelid" }, );
__PACKAGE__->belongs_to("protein", "PsdbProtein", { proteinid =>
"proteinid" });
 
in PoseDB::PsdbPose:
__PACKAGE__->belongs_to("parameter", "PsdbParameter", { paramid =>
"paramid" }); __PACKAGE__->belongs_to("model", "PsdbModel", { modelid =>
"modelid" }); __PACKAGE__->belongs_to("compcorp", "CompCorp", {
compound_id => "molid"
});
 
and in PoseDB::PsdbProtein:
__PACKAGE__->has_many(
  "models",
  "PsdbModel",
  { "foreign.proteinid" => "self.proteinid" }, );

The query looks like:
 
my $rs = $schema->resultset('PoseDB::PsdbPose')->search(
    { 'compcorp.alternate_id' => { in => [ 'LIB0031, 'LIB0032' } },
    {
        prefetch    => [ 'compcorp', { model => 'protein' } ],
        order_by => [qw/compcorp.alternate_id protein.proteinname
model.version posequality/],
    }
);
while ( my $pose = $rs->next ) {
    print join " , ",$pose->compcorp->compound_id,
$pose->compcorp->alternate_id, $pose->model->protein->proteinname;
    print "\n";
}
 
this works perfectly fine. But in this case all fields are returned
including a number of clobs en blobs. Actually these date are not needed
at this stage. So I decided to exclude those columns.
In order to accomplish that I changed the attributes to:
    {
        columns => $columns,
        join    => [ 'compcorp', { model => 'protein' } ],
        order_by => [qw/compcorp.alternate_id protein.proteinname
model.version posequality/],
    }

$columns is an array ref containing only the fields I need.

When I run this I have an error (at the next() method call), saying:
DBIx::Class::ResultSet::next(): No such relationship 'protein'
The statement itself looks perfectly healthy so it seems (DBIC_TRACE=1)
and looks exactly the same as the one before, but as expected, omitting
the blobs and clobs.
This exception only occurs when I add 'protein.proteinname' or
'protein.proteinid' to the columns array.
 
What am I doing wrong here ?
 
Regards,
Marc



 



More information about the Dbix-class mailing list