[Dbix-class] Prefetch Problem: Related data can't be fetched
sindharta_tanuwijaya at yahoo.co.jp
sindharta_tanuwijaya at yahoo.co.jp
Tue Feb 26 02:41:29 GMT 2008
Hi,
I am having a problem, in which I couldn't get the relationship column data by using prefetch.
My relationship is declared like this, suppose we have two tables: railway and railway_station, which relationship is 1 to many.
#in railway schema
__PACKAGE__->has_many(
"railway_station",
"Schema::RailwayStation",
{ "foreign.railway_station_railway_id" => "self.railway_id" },
);
#in railway_station schema
__PACKAGE__->belongs_to(
"railway",
"Schema::Railway",
{ "foreign.railway_id" => "self.railway_station_railway_id" },
);
My prefetch command is as follows:
my $railways = $schema->resultset('Railway')->search(
{
'me.railway_id' => { 'IN' => $selected_railway_ids },
},
{
join => 'railway_station',
prefetch => 'railway_station',
}
);
I could get the values of the columns of the railways correctly, but not the columns of railway_stations.
If I use 'join' only though, I could get all the data for railways which only have 1 row of railway_station, but not for
railways which have more than 1 rows of railway_station.
Any ideas why this happened ?
I have a hunch that maybe it's the ID of the railway_station that is causing this problem. In our current database, the primary key of
railway_station works as a dummy field, in which there are a lot of null values (although they are primary keys).
Of course, I have my own objections to this current implementation, but I am wondering if that is indeed the problem, since the primary key of railway_station isn't supposed to be used in any query generated above ?
Or maybe I am missing something else here.
Regards,
Sindharta
---------------------------------
Easy + Joy + Powerful = Yahoo! Bookmarks x Toolbar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080226/29d2443a/attachment.htm
More information about the DBIx-Class
mailing list