[Dbix-class] Question about relationship result caching

Mike Henson mdh2112 at speakeasy.net
Mon Jun 18 10:20:24 GMT 2007


> On Sat, Jun 16, 2007 at 10:22:45PM -0700, Mike Henson wrote:
> > Hello,
> > 
> > If I call a relationship accessor are the resulting objects it
> produces
> > cached or is the query sent to the db every time?
> > 
> > Example:
> > 
> > =====
> > # Very basic relationship snippets
> > package Example::Shelf;
> > __PACKAGE__->table('shelf');
> > __PACKAGE__->belongs_to( 'books' => 'Example::Books' );
> 
> I think you wanted has_many there if its plural books.
> 
> The query will normally be re-run, but you can later the behaviour by
> doing (fixing your Books -> Book class naming error)
> 
> __PACKAGE__->has_many('books' => 'Example::Book', undef, { cache =>
> 1 });
> 
> Note that if you prefetched the books when grabbing your shelf
> object(s)
> this would happen automatically.

Thanks for working through my bad example. I missed the line in the pod
that says "In addition to standard result set attributes...".

Mike
-- 




More information about the Dbix-class mailing list