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} } : $_;
}
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 {
}
}
}
- 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 {
)->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}}
);
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");
#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;