[Dbix-class] Merging ResultSets

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

On Tue, Apr 18, 2017 at 05:20:55PM +0300, Vladimir Melnik wrote:
> On Tue, Apr 18, 2017 at 02:43:55PM +0100, Dagfinn Ilmari Mannsåker wrote:
> > What you are looking for is the 'union_all' method from
> > https://metacpan.org/pod/DBIx::Class::Helper::ResultSet::SetOperations
> Thank you very much, it's exactly what I've been looking for!

Note that if you don't need an actual UNION query you can also do -

  my $merged = $schema->resultset('Foo');
  $merged->set_cache([ map $_->all, $rs1, $rs2, $rs3 ]);

and then iterating $merged will just use the cache.

This may or may not be better, depending on your goal.

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