=cut
sub search_related {
- my $self = shift;
- my $rel = shift;
- my $rs = $self->related_resultset($rel);
- if( @_ ) {
- return $rs->search(@_);
- }
- else {
- # search() returns a new resultset, so related_resultsets would be lost
- return wantarray ? $rs->all : $rs;
- }
+ return shift->related_resultset(shift)->search(@_);
}
=head2 count_related
my $self = shift;
#use Data::Dumper;warn Dumper(@_);
+ my $rs;
+ if( @_ ) {
+
+ my $attrs = { %{$self->{attrs}} };
+ if (@_ > 1 && ref $_[$#_] eq 'HASH') {
+ $attrs = { %$attrs, %{ pop(@_) } };
+ }
- my $attrs = { %{$self->{attrs}} };
- if (@_ > 1 && ref $_[$#_] eq 'HASH') {
- $attrs = { %$attrs, %{ pop(@_) } };
- }
-
- my $where = (@_ ? ((@_ == 1 || ref $_[0] eq "HASH") ? shift : {@_}) : undef());
- if (defined $where) {
- $where = (defined $attrs->{where}
+ my $where = (@_ ? ((@_ == 1 || ref $_[0] eq "HASH") ? shift : {@_}) : undef());
+ if (defined $where) {
+ $where = (defined $attrs->{where}
? { '-and' =>
[ map { ref $_ eq 'ARRAY' ? [ -or => $_ ] : $_ }
$where, $attrs->{where} ] }
: $where);
- $attrs->{where} = $where;
- }
-
- my $rs = (ref $self)->new($self->result_source, $attrs);
+ $attrs->{where} = $where;
+ }
+ $rs = (ref $self)->new($self->result_source, $attrs);
+ }
+ else {
+ $rs = $self;
+ $rs->reset();
+ }
return (wantarray ? $rs->all : $rs);
}