$attrs->{select} = [ map { m/\./ ? $_ : "${alias}.$_" } @cols ];
}
$attrs->{as} ||= [ map { m/^$alias\.(.*)$/ ? $1 : $_ } @{$attrs->{select}} ];
+ if (my $include = delete $attrs->{include_columns}) {
+ 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 } ];
if (my $join = delete $attrs->{join}) {
my $query;
if (ref $vals[0] eq 'HASH') {
- $query = $vals[0];
+ $query = { %{$vals[0]} };
} elsif (@cols == @vals) {
$query = {};
@{$query}{@cols} = @vals;
} else {
$query = {@vals};
}
+ foreach (keys %$query) {
+ next if m/\./;
+ $query->{$self->{attrs}{alias}.'.'.$_} = delete $query->{$_};
+ }
#warn Dumper($query);
return $self->search($query)->next;
}
with to find the number of elements. If passed arguments, does a search
on the resultset and counts the results of that.
+Note: When using C<count> with C<group_by>, L<DBIX::Class> emulates C<GROUP BY>
+using C<COUNT( DISTINCT( columns ) )>. Some databases (notably SQLite) do
+not support C<DISTINCT> with multiple columns. If you are using such a
+database, you should only use columns from the main table in your C<group_by>
+clause.
+
=cut
sub count {
C<me.> onto the start of any column without a C<.> in it and sets C<select>
from that, then auto-populates C<as> from C<select> as normal.
+=head2 include_columns (arrayref)
+
+Shortcut to include additional columns in the returned results - for example
+
+ { include_columns => ['foo.name'], join => ['foo'] }
+
+would add a 'name' column to the information passed to object inflation
+
=head2 select (arrayref)
Indicates which columns should be selected from the storage. You can use
=head2 group_by (arrayref)
-A arrayref of columns to group by. Can include columns of joined tables. Note
-note that L</count> doesn't work on grouped resultsets.
+A arrayref of columns to group by. Can include columns of joined tables.
group_by => [qw/ column1 column2 ... /]