On Wed, 02 May 2012 18:34:01 +0100, Robert wrote:

> What is the best way to modify customize the person method to memoize
> people, so that I can code the naive way (which is easier to read) but have
> DBIC do the right thing?

A way is to use prefetch, when you are getting the events; i.e.
something along the lines of:

  my $events=$schema->resultset('Result::Event')->search({}, { 
prefetch=>'person' });
  while (my $event=$events->next) {
      my $person=$event->person;
      # ...
  }

This tells DBIx::Class to join the person table on the event table and
person objects are then generated for you from that single query.

Running your script with DBIC_TRACE=1 set in the environment is an easy
way to check that prefetching indeed saves you roundtrips to the
database.


  Best regards,

    Adam

-- 
 "You have to photosynthesize"                                Adam Sjøgren
                                                         [email protected]

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to