}
my @unique_queries = $self->_unique_queries($input_query, $attrs);
-# use Data::Dumper; warn Dumper $self->result_source->name, $input_query, \@unique_queries, $self->{attrs}->{where};
# Handle cases where the ResultSet defines the query, or where the user is
# abusing find
my ($self, $query) = @_;
my $collapsed = $self->_collapse_query($query);
-# use Data::Dumper; warn Dumper $query, $collapsed;
foreach my $name ($self->result_source->unique_constraint_names) {
my @unique_cols = map { "$self->{attrs}->{alias}.$_" }
$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') {
+ foreach my $j (ref $join eq 'ARRAY' ? @$join : ($join)) {
+ if (ref $j eq 'HASH') {
$seen{$_} = 1 foreach keys %$j;
- } else {
+ } else {
$seen{$j} = 1;
- }
- }
+ }
+ }
- push(@{$attrs->{from}}, $source->resolve_join($join, $attrs->{alias}, $attrs->{seen_join}));
+ push(@{$attrs->{from}}, $source->resolve_join($join, $attrs->{alias}, $attrs->{seen_join}));
}
$attrs->{group_by} ||= $attrs->{select} if delete $attrs->{distinct};
$attrs->{order_by} = [ $attrs->{order_by} ] if
my $self = shift;
return $self->search(@_)->count if @_ and defined $_[0];
return scalar @{ $self->get_cache } if $self->get_cache;
-
my $count = $self->_count;
return 0 unless $count;
# offset, order by and page are not needed to count. record_filter is cdbi
delete $attrs->{$_} for qw/rows offset order_by page pager record_filter/;
- my ($count) = (ref $self)->new($self->result_source, $attrs)->cursor->next;
+ my $tmp_rs = (ref $self)->new($self->result_source, $attrs);
+ $tmp_rs->{_parent_rs} = $self->{_parent_rs} if ($self->{_parent_rs}); #XXX - hack to pass through parent of related resultsets
+
+ my ($count) = $tmp_rs->cursor->next;
return $count;
}
{ %{$self->{attrs}},
select => undef,
as => undef,
- join => $rel,
- _live_join => $rel }
+ join => $rel,
+ _live_join => $rel }
);
# keep reference of the original resultset
my $schema = DBICTest->init_schema();
-plan tests => 5;
+plan tests => 6;
+
+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 $rs1 = $schema->resultset("Artist")->search({ 'tags.tag' => 'Blue' }, { join => {'cds' => 'tracks'}, prefetch => {'cds' => 'tags'} });
my @artists = $rs1->all;
my @cds = $artists2[0]->cds;
cmp_ok(scalar @cds, '==', 1, "condition based on inherited join okay");
-my $rs3 = $rs2->search_related('cds')->search({'title' => 'Forkful of bees'});
-cpm_ok($rs3->count, '==', 3, "Three artists returned");
-exit;
+# this is wrong, should accept me.title really
+my $rs3 = $rs2->search_related('cds')->search({'cds.title' => 'Forkful of bees'});
+
+cmp_ok($rs3->count, '==', 3, "Three artists returned");
my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, { join => ['tracks', 'artist'], prefetch => 'artist' });
my @rs4_results = $rs4->all;