Renamed Visitor to Validator::Visitor to conform with Data::DPath::Validator and...
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / RequestArguments.pm
index a2fee74..e2b2775 100644 (file)
@@ -10,8 +10,6 @@ use namespace::autoclean;
 
 use Catalyst::Controller::DBIC::API::JoinBuilder;
 
-=for Pod::Coverage check_rel
-
 =attribute_private search_validator
 
 A Catalyst::Controller::DBIC::API::Validator instance used solely to validate search parameters
@@ -199,13 +197,13 @@ Like the synopsis in DBIC::API shows, you can declare a "template" of what is al
         {
             my ($self, $new) = @_;
 
-            sub check_rel {
+            sub _check_rel {
                 my ($self, $rel, $static) = @_;
                 if(ArrayRef->check($rel))
                 {
                     foreach my $rel_sub (@$rel)
                     {
-                        $self->check_rel($rel_sub, $static);
+                        $self->_check_rel($rel_sub, $static);
                     }
                 }
                 elsif(HashRef->check($rel))
@@ -225,7 +223,7 @@ Like the synopsis in DBIC::API shows, you can declare a "template" of what is al
 
             foreach my $rel (@$new)
             {
-                $self->check_rel($rel, $p->static);
+                $self->_check_rel($rel, $p->static);
             }
         },
     );
@@ -518,8 +516,9 @@ generate_column_parameters recursively generates properly aliased parameters for
         # build up condition
         foreach my $column (keys %$param)
         {
-            if($source->has_relationship($column))
+            if ($source->has_relationship($column))
             {
+                # check if the value isn't a hashref
                 unless (ref($param->{$column}) && reftype($param->{$column}) eq 'HASH')
                 {
                     $search_params->{join('.', $base, $column)} = $param->{$column};
@@ -536,10 +535,22 @@ generate_column_parameters recursively generates properly aliased parameters for
                     )
                 }};
             }
-            else
+            elsif ($source->has_column($column))
             {
                 $search_params->{join('.', $base, $column)} = $param->{$column};
             }
+            # might be a sql function instead of a column name
+            # e.g. {colname => {like => '%foo%'}}
+            else
+            {
+                # but only if it's not a hashref
+                unless (ref($param->{$column}) && reftype($param->{$column}) eq 'HASH') {
+                    $search_params->{join('.', $base, $column)} = $param->{$column};
+                }
+                else {
+                    die "$column is neither a relationship nor a column\n";
+                }
+            }
         }
 
         return $search_params;
@@ -576,6 +587,7 @@ This builder method generates the search attributes
             as => $self->as || ((scalar(@{$static->as})) ? $static->as : undef),
             prefetch => $self->prefetch || $static->prefetch || undef,
             rows => $self->count || $static->count,
+            page => $static->page,
             offset => $self->offset,
             join => $self->build_joins,
         };