X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=c65dc0bd7e1106ebc03e4b09e17abbf155a0434d;hb=5ac6a04477849fabc50271c5b7ab15a080ae0109;hp=f3617e7bbf82aa2c6956cd52da06320dcde59383;hpb=15c382bed3d8034f368386bd67236b8f342c1f25;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index f3617e7..c65dc0b 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -78,6 +78,10 @@ sub new { $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}) { @@ -224,13 +228,17 @@ sub find { 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; } @@ -368,6 +376,12 @@ Performs an SQL C with the same query as the resultset was built 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 with C, L emulates C +using C. Some databases (notably SQLite) do +not support C with multiple columns. If you are using such a +database, you should only use columns from the main table in your C +clause. + =cut sub count { @@ -710,6 +724,14 @@ Shortcut to request a particular set of columns to be retrieved. Adds C onto the start of any column without a C<.> in it and sets C 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 @@ -932,8 +954,7 @@ Can also be used to simulate an SQL C. =head2 group_by (arrayref) -A arrayref of columns to group by. Can include columns of joined tables. Note -note that L doesn't work on grouped resultsets. +A arrayref of columns to group by. Can include columns of joined tables. group_by => [qw/ column1 column2 ... /]