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

Christopher Heschong chris at wiw.org
Sat Jan 27 02:53:24 GMT 2007


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!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2409 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070126/e2b5a426/smime.bin


More information about the Dbix-class mailing list