[Dbix-class] Applying Result's methods to the whole ResultSet

James Gilbert jgrg at sanger.ac.uk
Tue Apr 18 16:50:44 GMT 2017


Oh, and this will work, almost.  You don't need the "->all".  The has_many('bars') relation creates a 'bars' method on each Foo Result object:

  foreach my $r_bar (map { $_->bars } $rs_foo->all) {
    $r_bar->some_method;
  }

For speed, prefetch bars.

> On 18 Apr 2017, at 16:59, Vladimir Melnik <v.melnik at uplink.ua> wrote:
> 
> ...or something like like that:
> 	# MyApp::Schema::Result::Foo->has_many('bars', 'MyApp::Schema::Result::Bar', { ... });
> 	my $rs_foo = $schema->resultset('Foo')->search({ ... });
> 	foreach my $r_bar (map { $_->bars->all } $rs_foo->all) {
> 	    $r_bar->some_method;
> 	}



-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 



More information about the DBIx-Class mailing list