From: Matt S Trout Date: Sun, 9 Jul 2006 23:29:44 +0000 (+0000) Subject: tweaked some stuff. appears no more broken. X-Git-Tag: v0.07002~75^2~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0596c69b942ab6f63c4f5a767161c1b4f79865b;p=dbsrgits%2FDBIx-Class.git tweaked some stuff. appears no more broken. --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index f4dcd65..7a405ce 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -157,6 +157,12 @@ always return a resultset, even in list context. sub search_rs { my $self = shift; + my $rows; + + unless (@_) { # no search, effectively just a clone + $rows = $self->get_cache; + } + my $attrs = {}; $attrs = pop(@_) if @_ > 1 and ref $_[$#_] eq 'HASH'; my $our_attrs = exists $attrs->{_parent_attrs} @@ -236,11 +242,8 @@ sub search_rs { my $rs = (ref $self)->new($self->result_source, $new_attrs); $rs->{_parent_source} = $self->{_parent_source} if $self->{_parent_source}; - unless (@_) { # no search, effectively just a clone - my $rows = $self->get_cache; - if ($rows) { - $rs->set_cache($rows); - } + if ($rows) { + $rs->set_cache($rows); } return $rs; } @@ -700,13 +703,14 @@ sub _resolved_attrs { my $self = shift; return $self->{_attrs} if $self->{_attrs}; - my $attrs = $self->{attrs}; + my $attrs = { %{$self->{attrs}||{}} }; my $source = $self->{_parent_source} || $self->{result_source}; my $alias = $attrs->{_orig_alias}; # XXX - lose storable dclone my $record_filter = delete $attrs->{record_filter}; - $attrs = Storable::dclone($attrs || {}); # { %{ $attrs || {} } }; + #$attrs = Storable::dclone($attrs || {}); # { %{ $attrs || {} } }; + $attrs = { %{ $attrs || {} } }; $attrs->{record_filter} = $record_filter if $record_filter; $attrs->{columns} ||= delete $attrs->{cols} if exists $attrs->{cols}; @@ -741,15 +745,7 @@ sub _resolved_attrs { $attrs->{from} ||= [ { $alias => $source->from } ]; $attrs->{seen_join} ||= {}; - my %seen; if (my $join = delete $attrs->{join}) { - foreach my $j (ref $join eq 'ARRAY' ? @$join : ($join)) { - if (ref $j eq 'HASH') { - $seen{$_} = 1 foreach keys %$j; - } else { - $seen{$j} = 1; - } - } push(@{$attrs->{from}}, $source->resolve_join($join, $alias, $attrs->{seen_join}) ); @@ -766,15 +762,6 @@ sub _resolved_attrs { if (my $prefetch = delete $attrs->{prefetch}) { my @pre_order; foreach my $p (ref $prefetch eq 'ARRAY' ? @$prefetch : ($prefetch)) { - if ( ref $p eq 'HASH' ) { - foreach my $key (keys %$p) { - push(@{$attrs->{from}}, $source->resolve_join($p, $alias)) - unless $seen{$key}; - } - } else { - push(@{$attrs->{from}}, $source->resolve_join($p, $alias)) - unless $seen{$p}; - } # bring joins back to level of current class $p = $self->_reduce_joins($p, $attrs) if $attrs->{_live_join_stack}; if ($p) { diff --git a/t/76joins.t b/t/76joins.t index 5755953..76e74fa 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -311,9 +311,9 @@ is($tree_like->children->first->children->first->name, 'quux', 'Tree search_rela $tree_like = $schema->resultset('TreeLike')->search( { 'children.id' => 2, 'children_2.id' => 5 }, { join => [qw/children children/] } - )->search_related('children', { 'children_3.id' => 3 }, { prefetch => 'children' } + )->search_related('children', { 'children_3.id' => 6 }, { prefetch => 'children' } )->first->children->first; -is($tree_like->name, 'baz', 'Tree with multiple has_many joins ok'); +is($tree_like->name, 'fong', 'Tree with multiple has_many joins ok'); # test that collapsed joins don't get a _2 appended to the alias diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index e64f796..a050862 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -197,6 +197,7 @@ sub populate_schema { [ 5, 1, 'blop' ], [ 3, 2, 'baz' ], [ 4, 3, 'quux' ], + [ 6, 2, 'fong' ], ]); $schema->populate('Track', [