[Dbix-class] Merging ResultSets
Dagfinn Ilmari Mannsåker
ilmari at ilmari.org
Tue Apr 18 13:43:55 GMT 2017
Vladimir Melnik <v.melnik at uplink.ua> writes:
> Hello,
>
> Is that possible to merge multiple ResultSets into one? For example,
> I’ve got 3 different ResultSets (as the yields of 3 different
> SQL-queries), but I’m pretty sure that they are based on the same
> class. Yes, I can work with their Results as with elements of a list,
> but sometimes it would be much more complicated to work with them as
> with a single ResultSet. Is that possible?
What you are looking for is the 'union_all' method from
https://metacpan.org/pod/DBIx::Class::Helper::ResultSet::SetOperations
> ...and here’s what I’d like to do:
> my $rs1 = $schema->resultset('Foo')->search({ bar => 1 });
> my $rs2 = $schema->resultset('Foo')->search({ bar => 2 });
> my $rs3 = $schema->resultset('Foo')->search({ bar => 3 });
> my $rs_merged = ...; # <-- Something cool happens here
my $rs_merged = $rs1->union_all([$rs2, $rs3]);
> foreach ($rs_merged->all) {
> $r->do_something;
> }
[…]
> Thanks in advance for any hints and clues!
Hope this helps!
- ilmari
--
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
the consequences of." -- Skud's Meta-Law
More information about the DBIx-Class
mailing list