From: Will Hawes Date: Sat, 18 Feb 2006 09:14:15 +0000 (+0000) Subject: maintain cache + reset cursor for search() without arguments X-Git-Tag: v0.06000~61^2~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ff7bb7a13a5254d5af455d17eeaa8b629d936183;p=dbsrgits%2FDBIx-Class.git maintain cache + reset cursor for search() without arguments --- diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 8925121..483ee98 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -84,16 +84,7 @@ sub register_relationship { } =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 diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index e0e321a..186a39c 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -152,24 +152,30 @@ sub search { 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); }