=cut
-# TODO: needs fixing
sub search_literal {
my ($self, $cond, @vals) = @_;
my $attrs = (ref $vals[$#vals] eq 'HASH' ? { %{ pop(@vals) } } : {});
my $query = @unique_queries ? \@unique_queries : undef;
# Run the query
+
if (keys %$attrs) {
my $rs = $self->search($query, $attrs);
- return $rs->{attrs}->{prefetch} ? $rs->next : $rs->single;
+ $rs->_resolve;
+ return keys %{$rs->{_attrs}->{collapse}} ? $rs->next : $rs->single;
}
else {
- return ($self->{attrs}->{prefetch})
+ $self->_resolve;
+ return (keys %{$self->{_attrs}->{collapse}})
? $self->search($query)->next
: $self->single($query);
}
# XXX - this is a hack to prevent dclone dieing because of the code ref, get's put back in $attrs afterwards
my $record_filter = delete $attrs->{record_filter} if (defined $attrs->{record_filter});
$attrs = Storable::dclone($attrs || {}); # { %{ $attrs || {} } };
+ $attrs->{record_filter} = $record_filter if ($record_filter);
+ $self->{attrs}->{record_filter} = $record_filter if ($record_filter);
+
my $alias = $attrs->{alias};
$attrs->{columns} ||= delete $attrs->{cols} if $attrs->{cols};
push(@{$attrs->{select}}, @$include);
push(@{$attrs->{as}}, map { m/([^.]+)$/; $1; } @$include);
}
- #use Data::Dumper; warn Dumper(@{$attrs}{qw/select as/});
$attrs->{from} ||= [ { $alias => $source->from } ];
$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
$attrs->{order_by} and !ref($attrs->{order_by});
push(@{$attrs->{order_by}}, @pre_order);
}
$attrs->{collapse} = $collapse;
- $attrs->{record_filter} = $record_filter if ($record_filter);
$self->{_attrs} = $attrs;
}
$self->_resolve;
my $attrs = { %{ $self->{_attrs} } };
- if (my $group_by = delete $attrs->{group_by}) {
+ if ($attrs->{distinct} && (my $group_by = $attrs->{group_by} || $attrs->{select})) {
delete $attrs->{having};
my @distinct = (ref $group_by ? @$group_by : ($group_by));
# todo: try CONCAT for multi-column pk
# 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;
return $count;
}
my @obj;
- # XXX used to be 'if (keys %{$self->{collapse}})'
- # XXX replaced by this as it seemed to do roughly the same thing
- # XXX could be bad as never really understood exactly what collapse did
- if ($self->{attrs}->{prefetch}) {
+ # TODO: don't call resolve here
+ $self->_resolve;
+ if (keys %{$self->{_attrs}->{collapse}}) {
+# if ($self->{attrs}->{prefetch}) {
# Using $self->cursor->all is really just an optimisation.
# If we're collapsing has_many prefetches it probably makes
# very little difference, and this is cleaner than hacking
sub run_tests {
my $schema = shift;
-plan tests => 55;
+plan tests => 57;
# figure out if we've got a version of sqlite that is older than 3.2.6, in
# which case COUNT(DISTINCT()) doesn't work
ok($art->update, 'Update run');
+my $record_jp = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search(undef, { prefetch => 'cds' })->next;
+
+ok($record_jp, "prefetch on same rel okay");
+
+my $record_fn = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search({'cds.cdid' => '1'}, {join => 'artist_undirected_maps'})->next;
+
+ok($record_fn, "funny join is okay");
+
@art = $schema->resultset("Artist")->search({ name => 'We Are In Rehab' });
cmp_ok(@art, '==', 1, "Changed artist returned by search");