[Dbix-class] prefetch problem
    Nigel Metheringham 
    nigel.metheringham at dev.intechnology.co.uk
       
    Fri Aug 13 14:53:10 GMT 2010
    
    
  
On 13 Aug 2010, at 15:39, Marc Perez wrote:
[Heavily edited down...]
> FIRST:
> package cmsDB::Files;
...
> __PACKAGE__->has_many(
> "fieldfiles",
> "cmsDB::Fieldfiles",
> { "foreign.file_id" => "self.file_id" },
> );
> When I try to access the fieldfiles data:
> 
> while( my $file = $files->next() ) {
> print($file->fieldfiles->name)
> }
You are treating the fieldfiles relationship above as though it was a 
belongs_to (or has_one) type relationship.
Instead $file->fieldfiles will return either a resultset of the
related rows (in scalar mode - which is what your example has),
or the matching rows in array mode, so you probably want:-
	while( my $file = $files->next() ) {
	  print($_->name) foreach ($file->fieldfiles);
	}
	Nigel.
--
[ Nigel Metheringham             Nigel.Metheringham at InTechnology.com ]
[ - Comments in this message are my own and not ITO opinion/policy - ]
    
    
More information about the DBIx-Class
mailing list