1DBIx::Class::Helper::ReUssuelrtSCeotn:t:rSiebaurtDceBhdIOxrP:(e:3rC)llaDsosc:u:mHeenltpaetri:o:nResultSet::SearchOr(3)
2
3
4

NAME

6       DBIx::Class::Helper::ResultSet::SearchOr - Combine ResultSet searches
7       with OR's
8

SYNOPSIS

10        package MyApp::Schema::ResultSet::Tests;
11
12        use parent 'DBIx::Class::ResultSet';
13
14        __PACKAGE__->load_components(qw(Helper::ResultSet::IgnoreWantarray Helper::ResultSet::SearchOr));
15
16        sub failed {
17          my $self = shift;
18
19          my $me = $self->current_source_alias;
20
21          $self->search({ "$me.passed" => '0' });
22        }
23
24        sub untested {
25          my $self = shift;
26
27          my $me = $self->current_source_alias;
28
29          $self->search({ "$me.passed" => undef });
30        }
31
32        sub not_passed {
33          my $self = shift;
34
35          my $me = $self->current_source_alias;
36
37          $self->search_or([$self->failed, $self->untested]);
38        }
39
40        1;
41

DESCRIPTION

43       I would argue that the most important feature of DBIx::Class is the
44       fact that you can "chain" ResultSet searches.  Unfortunately this can
45       cause problems when you need to reuse multiple ResultSet methods as...
46       well as or's.  In the past I got around this by doing:
47
48        $rs->foo->union([ $rs->bar]);
49
50       While this works, it can generate some hairy SQL pretty fast.  This
51       Helper is supposed to basically be a lightweight union.  Note that it
52       therefor has a number of "LIMITATIONS".  The thing that makes this
53       module special is that the ResultSet that is doing the "search_or" ing
54       still limits everything correctly.  To be clear, the following only
55       returns $user's friends that match either of the following criteria:
56
57        my $friend_rs = $schema->resultset('Friend');
58        my @internet_friends = $user->friends->search_or([
59          $friend_rs->on_facebook,
60          $friend_rs->on_twitter,
61        ])->all;
62
63       With a union, you'd have to implement it like this:
64
65        $user->friends->on_facebook->union([ $user->friends->on_twitter ]);
66
67       The union will work, but it will generate more complex SQL that may
68       have lower performance on your database.
69
70       See "NOTE" in DBIx::Class::Helper::ResultSet for a nice way to apply it
71       to your entire schema.
72

METHODS

74   search_or
75        my $new_rs = $rs->search_or([ $rs->foo, $rs->bar ]);
76
77       "search_or" takes a single arrayref of ResultSets.  The ResultSets must
78       point to the same source or you will get an error message.
79       Additionally, no check is made to ensure that more than one ResultSet
80       is in the ArrayRef, but only passing one ResultSet would not make any
81       sense.
82

LIMITATIONS

84       Because this module us basically an expression union and not a true
85       union, "JOIN"'s won't Just Work.  If you have a ResultSet method that
86       uses a "JOIN" and you want to "OR" it with another method, you'll need
87       to do something like this:
88
89        my @authors = $authors->search(undef, { join => 'books' })->search_or([
90           $authors->wrote_good_books,
91           $authors->wrote_bestselling_books,
92        ])->all;
93
94       Furthermore, if you want to "OR" two methods that "JOIN" in the same
95       relationship via alternate paths you must use union.
96

AUTHOR

98       Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
99
101       This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
102
103       This is free software; you can redistribute it and/or modify it under
104       the same terms as the Perl 5 programming language system itself.
105
106
107
108perl v5.32.0                      20D2B0I-x0:7:-C2l8ass::Helper::ResultSet::SearchOr(3)
Impressum