document including literal SQL and values in a resultset with "columns"
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSet.pm
index 222e175..49a490f 100644 (file)
@@ -247,7 +247,7 @@ sub new {
     if $source->isa('DBIx::Class::ResultSourceHandle');
 
   $attrs = { %{$attrs||{}} };
-  delete @{$attrs}{qw(_sqlmaker_select_args _related_results_construction)};
+  delete @{$attrs}{qw(_last_sqlmaker_alias_map _related_results_construction)};
 
   if ($attrs->{page}) {
     $attrs->{rows} ||= 10;
@@ -1351,7 +1351,7 @@ sub _construct_results {
   return undef unless @{$rows||[]};
 
   # sanity check - people are too clever for their own good
-  if ($attrs->{collapse} and my $aliastypes = $attrs->{_sqlmaker_select_args}[3]{_aliastypes} ) {
+  if ($attrs->{collapse} and my $aliastypes = $attrs->{_last_sqlmaker_alias_map} ) {
 
     my $multiplied_selectors;
     for my $sel_alias ( grep { $_ ne $attrs->{alias} } keys %{ $aliastypes->{selecting} } ) {
@@ -2662,8 +2662,6 @@ sub as_query {
     $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs
   );
 
-  $self->{_attrs}{_sqlmaker_select_args} = $attrs->{_sqlmaker_select_args};
-
   $aq;
 }
 
@@ -3188,11 +3186,11 @@ sub related_resultset {
 
     if (my $cache = $self->get_cache) {
       my @related_cache = map
-        { @{$_->related_resultset($rel)->get_cache||[]} }
+        { $_->related_resultset($rel)->get_cache || () }
         @$cache
       ;
 
-      $new->set_cache(\@related_cache) if @related_cache;
+      $new->set_cache([ map @$_, @related_cache ]) if @related_cache == @$cache;
     }
 
     $new;
@@ -3993,6 +3991,13 @@ is the same as
     select => [qw/foo baz/],
     as => [qw/foo bar/]
 
+Like elsewhere, literal SQL or literal values can be included by
+using a scalar reference, and these values will be available in the result
+with C<get_column>:
+
+    # equivalent SQL: SELECT 1, "a string", IF(x,1,2) ...
+    columns => [ { foo => \1, bar => \'"a string"', baz => \'IF(x,1,2)' } ]
+
 =head2 +columns
 
 =over 4