[Dbix-class] accessing columns in multi-step prefetches

Peter Edwards peter at dragonstaff.com
Sat Jan 27 08:03:49 GMT 2007


So you have watching -> persons -> relations -> items

Does $thing->person->relation->item->title work from the prefetched data if
you turn DBIC_TRACE on?

Regards, Peter

-----Original Message-----
From: Christopher Heschong [mailto:chris at wiw.org] 
Sent: 27 January 2007 02:53
To: dbix-class at lists.rawmode.org
Subject: [Dbix-class] accessing columns in multi-step prefetches

So I have this code:

     my $rs = $self->search_related('watching', {},
         {
             select => [
                 { distinct => 'item.id' }
             ],
             prefetch => { person => { relations => 'item' } },
             join => {
                 'person' => {
                     'relations' => 'item'
                 }
             },
             order_by => 'item.releasedate DESC',
             page => 1,
             rows => $count
         }
     );

     $thing = $rs->first;


Which produces this SQL on trace:

SELECT DISTINCT( item.id ), person.id, person.mtime, person.title,  
person.photo, person.refresh, relations.person, relations.item,  
relations.role, item.id, item.mtime, item.title, item.releasedate,  
item.type, item.manufacturer, item.asin, item.itms, item.photo,  
item.universal FROM watching me  JOIN persons person ON ( person.id =  
me.person ) LEFT JOIN relations relations ON ( relations.person =  
person.id )  JOIN items item ON ( item.id = relations.item ) WHERE  
( me.user = ? ) ORDER BY item.releasedate DESC, relations.person  
LIMIT 1: '1'


What I can't figure out is how to display the 'item.title' field from  
the $thing object.  All the person.* things are available, but not  
item.*

	$thing->person->title;	# works
	$thing->item->title; # Can't locate object method "item"

Do I need to do something different with my prefetch definition to  
get DBIx::Class to notice that I fetched the items table?

Thanks!





More information about the Dbix-class mailing list