[Dbix-class] prefetching and many_to_many

Matt S Trout dbix-class at trout.me.uk
Sat Aug 12 23:47:50 CEST 2006


Stanis Trendelenburg wrote:
> Matt S Trout wrote:
>> In a word, "yes". It's a limitation of the current implementation; patches 
>> welcome or one of the existing devs will get round to it when we have tuits.
> 
> OK, thanks for the clarification.
> 
> After reading some more of the documentation and looking at
> Relationship/ManyToMany.pm I see why this is the case.
> The many_to_many accessor returns a resultset created by
> 
>   $self->search_related($rel)->search_related($f_rel)
> 
> where $rel is the has_many relation from the original class to the
> mapping class, and $f_rel the belongs_to relation from the mapping class
> to the wanted class.
> If I understand this correctly, this new resultset has no information
> about the current object (like prefetched values).
> 
> What do you think of the following patch to the many_to_many accessor:
> When the accessor is called in list context without arguments, return
> the objects directly (which will use the prefetched values) instead
> of returning the resultset from search_related().

Weeel ... it's ok.

But wouldn't it be better to make search_related check the prefetch attr and 
copy the appropriate stuff from the cache instead?



More information about the Dbix-class mailing list