my %attrs = %{$self->{attrs}||{}};
delete $attrs{result_class};
- $self->_source_handle->schema->resultset($rel_obj->{class})->search_rs(
- undef, {
- %attrs,
- join => undef,
- prefetch => undef,
- select => undef,
- as => undef,
- alias => $alias,
- where => $self->{cond},
- seen_join => $seen,
- from => $from,
- });
+ my $new_cache;
+
+ if (my $cache = $self->get_cache) {
+ if ($cache->[0] && $cache->[0]->related_resultset($rel)->get_cache) {
+ $new_cache = [ map { @{$_->related_resultset($rel)->get_cache} }
+ @$cache ];
+ }
+ }
+
+ my $new = $self->_source_handle
+ ->schema
+ ->resultset($rel_obj->{class})
+ ->search_rs(
+ undef, {
+ %attrs,
+ join => undef,
+ prefetch => undef,
+ select => undef,
+ as => undef,
+ alias => $alias,
+ where => $self->{cond},
+ seen_join => $seen,
+ from => $from,
+ });
+ $new->set_cache($new_cache) if $new_cache;
+ $new;
};
}
$fetched = $pre_source->result_class->inflate_result(
$pre_source, @{$pre_val});
}
+ $new->related_resultset($pre)->set_cache([ $fetched ]);
my $accessor = $source->relationship_info($pre)->{attrs}{accessor};
$class->throw_exception("No accessor for prefetched $pre")
unless defined $accessor;
cmp_ok($rs + 0, '==', 3, 'Correct number of records returned');
my $queries = 0;
-$schema->storage->debugcb(sub { $queries++ });
+$schema->storage->debugcb(sub { $queries++; });
$schema->storage->debug(1);
my @cd = $rs->all;
'Caterwauler McCrae',
'chained belongs_to->belongs_to search_related ok');
-TODO: {
- local $TODO = 'use prefetched values for nested search_related';
-
- is($queries, 0, 'chained search_related after belontgs_to->belongs_to prefetch ran no queries');
-}
+is($queries, 0, 'chained search_related after belontgs_to->belongs_to prefetch ran no queries');
$queries = 0;
$queries = 0;
+$schema->storage->debugcb(sub { $queries++; warn "Q: @_"; });
+
$cd = $schema->resultset('CD')->find(1, { prefetch => { cd_to_producer => 'producer' } });
is($cd->producers->first->name, 'Matt S Trout', 'many_to_many accessor ok');
is($producers->first->name, 'Matt S Trout', 'chained many_to_many search_related ok');
-TODO: {
- local $TODO = 'use prefetched values for search_related';
-
- is($queries, 0, 'chained search_related after many_to_many prefetch ran no queries');
-}
+is($queries, 0, 'chained search_related after many_to_many prefetch ran no queries');
$schema->storage->debug($orig_debug);
$schema->storage->debugobj->callback(undef);
{},
{
join => [ { cds => ['tracks'] } ],
- prefetch => [ { cds => ['tracks'] } ]
+ prefetch => [ { cds => ['tracks'] } ],
+ cache => 1 # last test needs this
}
);
'chained has_many->has_many search_related ok'
);
-TODO: {
- local $TODO ='use prefetched values for chained search_related';
-
- is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries');
-}
+is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries');