[Dbix-class] Question about relationship result caching
Matt S Trout
dbix-class at trout.me.uk
Sun Jun 17 16:48:41 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.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
More information about the Dbix-class
mailing list