[Dbix-class] totally simplified example of my prefetch problem.

George Hartzell hartzell at alerce.com
Mon Aug 14 20:14:11 CEST 2006


Matt S Trout writes:
 > George Hartzell wrote:
 > > I've put together a dead-simple example that demonstrates the problem
 > > that I'm having using prefetch.  Three tables, 4 rows of data in
 > > total, simple driver script, etc....
 > 
 > You can only prefetch one "direction" of has_many rels at once. Anything else 
 > results in a cross-product return of records which tends to be heinously 
 > inefficient anyway.
 > 
 > i.e.
 > 
 > [ 'hm_rel', 'other_hm_rel' ] won't work
 > 
 > although
 > 
 > [ { 'hm_rel' => { 'belongs_to_rel' => 'ya_hm_rel' }, 'other_belongs_to_rel' ]
 > 
 > and similar are fine.

Ok.

So, working with the example that I posted, what's the most effecient
thing to do if you want to get back an "A" and all that goes with it?

Sounds like I just have to pick whether I'm more likely to monkey with
the A's b's or c's and just prefetch one or the other.

Right?

Given that I tend to do this (and assuming that I haven't prefetched
the b rows)

  grep {$_->b_name eq 'MOOSE'} $a->bs();

is there some way to use cache=>1 to my advantage?

Thanks,

g.




More information about the Dbix-class mailing list