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

Matt S Trout mst at shadowcat.co.uk
Wed Apr 19 00:21:28 GMT 2017

On Tue, Apr 18, 2017 at 06:59:48PM +0300, Vladimir Melnik wrote:
> Hello,
> And one more question, if anyone doesn't mind. :-)
> Is there an elegant way to apply a Result's method to the whole ResultSet?
> In other words, here's what I have to do:
> 	# MyApp::Schema::Result::Foo->has_many('bars', 'MyApp::Schema::Result::Bar', { ... });
> 	my $rs_foo = $schema->resultset('Foo')->search({ ... });

  $_->some_method for map $_->bars->all, $rs_foo->all;


  $_->some_method for $rs_foo->search_related('bars')->all;

(I would always explicitly call the ->all for clarity)

Matt S Trout - Shadowcat Systems - Perl consulting with a commit bit and a clue

http://shadowcat.co.uk/blog/matt-s-trout/   http://twitter.com/shadowcat_mst/

Email me now on mst (at) shadowcat.co.uk and let's chat about how our CPAN
commercial support, training and consultancy packages could help your team.

More information about the DBIx-Class mailing list