1DBIx::Class::Helper::ReUssuelrtSCeotn:tD:rBSiIebxtu:Ot:peCedlraaPstesir:ol:nHsDe(ol3cp)uemre:n:tRaetsiuolntSet::SetOperations(3)
2
3
4

NAME

6       DBIx::Class::Helper::ResultSet::SetOperations - Do set operations with
7       DBIx::Class
8

SYNOPSIS

10        package MyApp::Schema::ResultSet::Foo;
11
12        __PACKAGE__->load_components(qw{Helper::ResultSet::SetOperations});
13
14        ...
15
16        1;
17
18       And then elsewhere, like in a controller:
19
20        my $rs1 = $rs->search({ foo => 'bar' });
21        my $rs2 = $rs->search({ baz => 'biff' });
22        for ($rs1->union($rs2)->all) { ... }
23

DESCRIPTION

25       This component allows you to use various set operations with your
26       ResultSets.  See "NOTE" in DBIx::Class::Helper::ResultSet for a nice
27       way to apply it to your entire schema.
28
29       Component throws exceptions if ResultSets have different ResultClasses
30       or different "Columns Specs."
31
32       The basic idea here is that in SQL if you use a set operation they must
33       be selecting the same columns names, so that the results will all
34       match.  The deal with the ResultClasses is that DBIC needs to inflate
35       the results the same for the entire ResultSet, so if one were to try to
36       apply something like a union in a table with the same column name but
37       different classes DBIC wouldn't be doing what you would expect.
38
39       A nice way to use this is with
40       DBIx::Class::ResultClass::HashRefInflator.
41
42       You might have something like the following sketch autocompletion code:
43
44        my $rs1 = $schema->resultset('Album')->search({
45           name => { -like => "$input%" }
46        }, {
47          columns => [qw( id name ), {
48             tablename => \['?', [{} => 'album']],
49          }],
50        });
51
52        my $rs2 = $schema->resultset('Artist')->search({
53           name => { -like => "$input%" }
54        }, {
55          columns => [qw( id name ), {
56             tablename => \['?', [{} => 'artist']],
57          }],
58        });
59
60        my $rs3 = $schema->resultset('Song')->search({
61           name => { -like => "$input%" }
62        }, {
63          columns => [qw( id name ), {
64             tablename => \['?', [{} => 'song']],
65          }],
66        });
67
68        $_->result_class('DBIx::Class::ResultClass::HashRefInflator')
69          for ($rs1, $rs2, $rs3);
70
71        my $data = [$rs1->union([$rs2, $rs3])->all];
72

METHODS

74   union
75   union_all
76   intersect
77   intersect_all
78   except
79   except_all
80       All of these methods take a single ResultSet or an ArrayRef of
81       ResultSets as the parameter only parameter.
82
83       On Oracle "except" will issue a "MINUS" operation.
84

AUTHOR

86       Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
87
89       This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
90
91       This is free software; you can redistribute it and/or modify it under
92       the same terms as the Perl 5 programming language system itself.
93
94
95
96perl v5.36.0                  DBIx2:0:2C2l-a0s7s-:2:2Helper::ResultSet::SetOperations(3)
Impressum