use Storable;
use Data::Dumper;
use Scalar::Util qw/weaken/;
-
+use Data::Dumper;
use DBIx::Class::ResultSetColumn;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/AccessorGroup/);
my @asadds = (ref($asadds) eq 'ARRAY' ? @$asadds : ($asadds));
$attrs->{as} = [ @{ $attrs->{as} }, @asadds ];
}
-
my $collapse = $attrs->{collapse} || {};
if (my $prefetch = delete $attrs->{prefetch}) {
my @pre_order;
push(@{$attrs->{from}}, $source->resolve_join($p, $attrs->{alias}))
unless $seen{$p};
}
+ #print "res pre: " . Dumper($p, $collapse);
my @prefetch = $source->resolve_prefetch(
$p, $attrs->{alias}, {}, \@pre_order, $collapse);
+
+ #print "prefetch: " . Dumper(\@prefetch);
push(@{$attrs->{select}}, map { $_->[0] } @prefetch);
push(@{$attrs->{as}}, map { $_->[1] } @prefetch);
}
if (exists $a->{$key}) {
$a->{$key} = $self->_merge_attr($a->{$key}, $b->{$key}, $is_prefetch);
} else {
- $a->{$key} = delete $b->{$key};
+ $a->{$key} = $b->{$key};
}
}
return $a;
my ($self, @row) = @_;
my @as = @{ $self->{_attrs}{as} };
+ #print "row in: " . Dumper(\@row);
my $info = $self->_collapse_result(\@as, \@row);
my $new = $self->result_class->inflate_result($self->result_source, @$info);
$new = $self->{_attrs}{record_filter}->($new)
$info->[0] = $const{$key};
}
}
-
my @collapse;
+
+ #print "collapse: " . Dumper($self->{_attrs}->{collapse});
if (defined $prefix) {
@collapse = map {
m/^\Q${prefix}.\E(.+)$/ ? ($1) : ()
}
my $c_prefix = (defined($prefix) ? "${prefix}.${c}" : $c);
my @co_key = @{$self->{_attrs}->{collapse}{$c_prefix}};
- my %co_check = map { ($_, $target->[0]->{$_}); } @co_key;
my $tree = $self->_collapse_result($as, $row, $c_prefix);
+ my %co_check = map { ($_, $tree->[0]->{$_}); } @co_key;
my (@final, @raw);
+
+ #print "les free: " . Dumper($tree->[0], \%co_check, \@co_key);
while ( !(grep {
!defined($tree->[0]->{$_}) ||
$co_check{$_} ne $tree->[0]->{$_}
@$target = (@final ? @final : [ {}, {} ]);
# single empty result to indicate an empty prefetched has_many
}
+
+ # get prefetch tree back to result_source level
+ # $self could be a related resultset
+ #if ($self->{attrs}->{_live_join_stack}) {
+ # foreach (@{$self->{attrs}->{_live_join_stack}}) {
+ # $info->[1] = $info->[1]->{$_}->[1] if(exists $info->[1]->{$_});
+ #}
+ #}
+ #print "final info: " . Dumper($info);
return $info;
}
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');
+# my $prod_rs = $schema->resultset("CD")->find(1)->other_producers;
+# my $prod_rs2 = $prod_rs->search({ name => 'Matt S Trout' }, { prefetch => 'producer_to_cd', order_by => 'other_producer.name' });
+# my $prod_first = $prod_rs2->first;
+# warn $prod_first->name;
+
+my $prod_map_rs = $schema->resultset("Artist")->find(1)->cds->search_related('cd_to_producer', {}, { join => 'producer', prefetch => 'producer' });
+use Data::Dumper;
+warn $prod_map_rs->count;
+print Dumper($prod_map_rs->{attrs});
+print Dumper($prod_map_rs->{_attrs});
+$prod_map_rs->first;
+
+
+
1;