From: Luke Saunders Date: Tue, 6 Jun 2006 23:49:10 +0000 (+0000) Subject: branch cleanage X-Git-Tag: v0.07002~75^2~130^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=48c9af026b923ad5d18542ae9a0a5f7ccae5ea35;p=dbsrgits%2FDBIx-Class.git branch cleanage --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 7a0d302..db246df 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -166,8 +166,8 @@ sub search_rs { my $having = delete $our_attrs->{having}; # XXX this is getting messy - if ($attrs->{_live_join_stack} || $our_attrs->{_live_join_stack}) { - my $live_join = $attrs->{_live_join_stack} || $our_attrs->{_live_join_stack}; + if ($attrs->{_live_join_stack}) { + my $live_join = $attrs->{_live_join_stack}; foreach (reverse @{$live_join}) { $attrs->{_live_join_h} = (defined $attrs->{_live_join_h}) ? { $_ => $attrs->{_live_join_h} } : $_; } @@ -178,13 +178,11 @@ sub search_rs { next unless (exists $attrs->{$key}); if ($attrs->{_live_join_stack} || $our_attrs->{_live_join_stack}) { my $live_join = $attrs->{_live_join_stack} || $our_attrs->{_live_join_stack}; - foreach (@{$live_join}) { + foreach (reverse @{$live_join}) { $attrs->{$key} = { $_ => $attrs->{$key} }; } } - if ($attrs->{_live_join} || $our_attrs->{_live_join}) { - $attrs->{$key} = { ($attrs->{_live_join}) ? $attrs->{_live_join} : $our_attrs->{_live_join} => $attrs->{$key} }; - } + if (exists $our_attrs->{$key}) { $our_attrs->{$key} = $self->_merge_attr($our_attrs->{$key}, $attrs->{$key}); } else { @@ -802,13 +800,13 @@ sub _merge_attr { } } } - if ($is_prefetch) { - my $final_array = []; - foreach my $element (@{$array}) { - push(@{$final_array}, $element) unless (exists $hash->{$element}); - } - $array = $final_array; - } + + my $final_array = []; + foreach my $element (@{$array}) { + push(@{$final_array}, $element) unless (exists $hash->{$element}); + } + $array = $final_array; + if ((keys %{$hash}) && (scalar(@{$array} > 0))) { return [$hash, @{$array}]; } else { @@ -1585,9 +1583,8 @@ sub related_resultset { )->search( undef, { select => undef, as => undef, - #join => $rel, - _live_join => $rel, - _live_join_stack => $live_join_stack, + _live_join => $rel, #the most recent + _live_join_stack => $live_join_stack, #the trail of rels _parent_attrs => $self->{attrs}} ); diff --git a/t/90join_torture.t b/t/90join_torture.t index c5a4bcf..b09e9f8 100644 --- a/t/90join_torture.t +++ b/t/90join_torture.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 10; +plan tests => 11; my @rs1a_results = $schema->resultset("Artist")->search_related('cds', {title => 'Forkful of bees'}, {order_by => 'title'}); is($rs1a_results[0]->title, 'Forkful of bees', "bare field conditions okay after search related"); @@ -49,7 +49,13 @@ is(scalar(@tracks), 3, 'right number of prefetched tracks after has many'); #my $tracks_rs = $cds->search_related('tracks', { 'tracks.position' => '2', 'disc.title' => 'Forkful of bees' }); #my $first_tracks_rs = $tracks_rs->first; -my ($track) = $schema->resultset("Artist")->search({ name => 'Caterwauler McCrae' })->search_related('cds', { year => '2001'})->search_related('tracks', { 'position' => '2' })->all; -is($track->trackid, '5', 'search related on search related okay'); +my $related_rs = $schema->resultset("Artist")->search({ name => 'Caterwauler McCrae' })->search_related('cds', { year => '2001'})->search_related('tracks', { 'position' => '2' }); +is($related_rs->first->trackid, '5', 'search related on search related okay'); + +# causes ambig col error due to order_by +#$related_rs->search({'cd.year' => '2001'}, {join => ['cd', 'cd']})->all; + +my $title = $schema->resultset("Artist")->search_related('twokeys')->search_related('cd')->search({'tracks.position' => '2'}, {join => 'tracks', order_by => 'tracks.trackid'})->next->title; +is($title, 'Forkful of bees', 'search relateds with order by okay'); 1;