[Dbix-class] ResultSet->search + prefetch
Ryan VanderBijl
ryan-dbix at vbijl.net
Mon Jan 8 15:12:56 GMT 2007
It seems to me that a search with prefetch does not take into
consideration the extra attributes specified in the prefetched
relationships' attributes.
My device class defines its relationships like this:
__PACKAGE__->might_have(
"current_name_object",
"myapp::Model::db::IcDevName",
{ "foreign.dev_id" => "self.dev_id" },
{ "where" => { "me.finished_date" => undef } },
);
__PACKAGE__->might_have(
"current_position",
"myapp::Model::db::IcDevCurrentPosition",
{ "foreign.dev_id" => "self.dev_id" },
{ "prefetch" => [ "description_object" ] }
);
Then using these relationships does what I expect: it only returns a
name_object where the finished_date is null, and getting the
current_position prefetches the descrition_object (checked with
DBIX_CLASS_STORAGE_DBI_DEBUG=1).
If I do a search:
my $rs = $schema->resultset("Device")->search(
{ account => 1 },
{ prefetch =>
[ qw/current_name_object current_position/ ]}
);
I get the wrong results. Using DBIX_CLASS_STORAGE_DBI_DEBUG=1, I
see that my current_name_object's WHERE clause is not included,
nor is my description_object prefetched.
The work-around for the missing prefetch isn't too bad:
prefetch => [ "current_name_object", { "current_position" =>
"description_object"} ]
But I don't like manually adding another search/filter parameter. Any
suggestions?
Thanks!
-Ryan
--
Ryan VanderBijl | http://vbijl.net/~ryan/
More information about the Dbix-class
mailing list