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

Christopher Heschong chris at wiw.org
Sun Jan 28 22:28:46 GMT 2007


Nope.  Person <--> Relations <--> Items is a many_to_many  
relationship, so $thing->person->relations doesn't return just the  
item I selected.  Maybe that's what is complicating this.

I also tried adding:

	\'item.title AS item_title'

to my select portion but that didn't work either (Can't locate object  
method "item_title")


On Jan 27, 2007, at 3:03 AM, Peter Edwards wrote:

>
> 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!
>
>
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive: http://www.mail-archive.com/dbix- 
> class at lists.rawmode.org/

-------------- 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/20070128/aafbd7aa/smime.bin


More information about the Dbix-class mailing list