[Dbix-class] Prefetch Problem: Related data can't be fetched

Matt Lawrence matt.lawrence at ymogen.net
Tue Feb 26 14:03:33 GMT 2008


Jess Robinson wrote:
>
> On Tue, 26 Feb 2008, Matt Lawrence wrote:
>
>> sindharta_tanuwijaya at yahoo.co.jp wrote:
>>> 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.
>>>
>>>
>>>
>> railway_station is a has_many relationship, so you can't prefetch it.
>> You could do it the other way around and prefetch "railway" from a
>> RailwayStation resultset however:
>
> Rubbish, whatever gave you that idea?

Docs say:

|prefetch| can be used with the following relationship types: 
|belongs_to|, |has_one| (or if you're using |add_relationship|, any 
relationship declared with an accessor type of 'single' or 'filter').


> You can indeed prefetch a has_many rel.
>
Excellent. How does that work? Do you get one instance of each object 
with a prepopulated resultset?


Matt




More information about the DBIx-Class mailing list