[Catalyst-commits] r9289 - in Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch: . lib/Catalyst/Controller/DBIC/API t/rest t/rpc

lukes at dev.catalyst.perl.org lukes at dev.catalyst.perl.org
Fri Feb 13 15:40:26 GMT 2009


Author: lukes
Date: 2009-02-13 15:40:26 +0000 (Fri, 13 Feb 2009)
New Revision: 9289

Modified:
   Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/
   Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm
   Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/REST.pm
   Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/RPC.pm
   Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t
   Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rpc/list.t
Log:
 r10478 at luke-mbp (orig r9148):  lukes | 2009-01-30 14:39:05 +0000
 failing test from abraxxa and fix for it
 r10479 at luke-mbp (orig r9149):  lukes | 2009-01-30 17:17:43 +0000
 object detaches if id is invalid
 r10480 at luke-mbp (orig r9150):  lukes | 2009-01-30 17:26:27 +0000
 failing test for ambigous column names in where
 r10498 at luke-mbp (orig r9172):  lukes | 2009-02-02 22:42:46 +0000
 fixed error case where col and rel have the same name



Property changes on: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch
___________________________________________________________________
Name: svk:merge
   - 4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Controller-DBIC-API/1.000/trunk:8157
   + 4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Controller-DBIC-API/1.000/trunk:8157
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Controller-DBIC-API/1.001/trunk:9172

Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm	2009-02-12 20:38:53 UTC (rev 9288)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/Base.pm	2009-02-13 15:40:26 UTC (rev 9289)
@@ -36,9 +36,7 @@
 
   my ($params, $args) = @{$c->forward('generate_dbic_search_args')};
 
-#  use Data::Dumper; warn Dumper($params, $args);
   $c->stash->{$self->rs_stash_key} = $c->stash->{$self->rs_stash_key}->search($params, $args);
-
   $c->forward('format_list');
 }
 
@@ -47,7 +45,6 @@
 
   # FIXME: expand_hash isn't called although it should have been
   my $req_params = (grep { ref $_ } values %{$c->req->params}) ? $c->req->params : $self->expand_hash($c->req->params);
-
   if ( my $a = $self->setup_list_method ) {
     my $setup_action = $self->action_for($a);
     if ( defined $setup_action ) {
@@ -56,7 +53,6 @@
       $c->log->error("setup_list_method was configured, but action $a not found");
     }
   }
-
   my $source = $c->stash->{$self->rs_stash_key}->result_source;
 
   my ($params, $join);
@@ -78,19 +74,22 @@
 	my $base = $p->{base} || 'me';
 
 	my $join = {};
-  # FIXME: detect params which might belong to a column and relationship
-  # with the same name
-  my %search_params = map { ($base) ? join('.', $base, $_) : $_ => $params->{$_} } grep {
-    exists $params->{$_}
-      # this check breaks so called 'complex searches'(column.LIKE=%foo%)
-      # in the test suite but makes sure that searches on a rel aren't
-      # added as column search params
-      && not ref $params->{$_}
-    } $source->columns;
+  my %relname_map = map { $_ => 1 } $source->relationships;
+  my %search_params;
 
+  # build up condition on root source
+  foreach my $column ($source->columns) {
+    next unless (exists $params->{$column});
+    # FIXME: we assume that if the value is a reference, then it can't
+    # be a base condition. but this is not true in the case of { col => { LIKE => '%stuff%' }
+    next if ($relname_map{$column} && ref $params->{$column});
 
-	my %search_params = map { ($base) ? join('.', $base, $_) : $_ => $params->{$_} } grep { exists $params->{$_} } $source->columns;
-	foreach my $rel ($source->relationships) {
+    $search_params{join('.', $base, $column)} = $params->{$column};
+  }
+
+  # build up related conditions
+	foreach my $rel (keys %relname_map) {    
+    next if ($search_params{join('.', $base, $rel)}); # if it's a condition on the base source, then it's can't also be a rel
     next if grep { warn $_; $rel eq $_ } $source->columns;
     # fixes a search on a column which has a relationship with the same name
     if (exists $params->{$rel} && ref $params->{$rel}) {
@@ -181,7 +180,6 @@
 	my %requires_map = map { $_ => 1 } @{($object->in_storage) ? [] : $c->stash->{create_requires} || $self->create_requires};
 	my %allows_map = map { (ref $_) ? %{$_} : ($_ => 1) } (keys %requires_map, @{($object->in_storage) ? ($c->stash->{update_allows} || $self->update_allows) : ($c->stash->{create_allows} || $self->create_allows)});
 	
-	use Data::Dumper; warn Dumper($params, \%requires_map, \%allows_map);
 	foreach my $key (keys %allows_map) {
 		# check value defined if key required
 		my $allowed_fields = $allows_map{$key};

Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/REST.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/REST.pm	2009-02-12 20:38:53 UTC (rev 9288)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/REST.pm	2009-02-13 15:40:26 UTC (rev 9289)
@@ -94,6 +94,7 @@
 	my $object = $c->stash->{$self->rs_stash_key}->find( $id );
 	unless ($object) {
 		$self->push_error($c, { message => "Invalid id" });
+		$c->detach; # no point continuing
 	}
 	$c->stash->{$self->object_stash_key} = $object;
 }

Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/RPC.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/RPC.pm	2009-02-12 20:38:53 UTC (rev 9288)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/lib/Catalyst/Controller/DBIC/API/RPC.pm	2009-02-13 15:40:26 UTC (rev 9289)
@@ -106,6 +106,7 @@
 	my $object = $c->stash->{$self->rs_stash_key}->find( $id );
 	unless ($object) {
 		$self->push_error($c, { message => "Invalid id" });
+		$c->detach; # no point continuing
 	}
 
 	$c->stash->{$self->object_stash_key} = $object;

Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t	2009-02-12 20:38:53 UTC (rev 9288)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rest/list.t	2009-02-13 15:40:26 UTC (rev 9289)
@@ -29,7 +29,6 @@
   }, 'Accept' => 'text/x-json' );
   $mech->request($req);
   cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
-        warn $mech->content;exit;
   my @expected_response = map { { $_->get_columns } } $schema->resultset('Artist')->all;
   my $response = JSON::Syck::Load( $mech->content);
   is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct message returned' );

Modified: Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rpc/list.t	2009-02-12 20:38:53 UTC (rev 9288)
+++ Catalyst-Controller-DBIC-API/1.001/branches/abraxxa_patch/t/rpc/list.t	2009-02-13 15:40:26 UTC (rev 9289)
@@ -150,3 +150,16 @@
   #use Data::Dumper; warn Dumper($response, \@expected_response);
   is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for search on column with same name rel' );
 }
+
+{
+  my $uri = URI->new( $cd_list_url );
+  $uri->query_form({ 'search.title' => 'Spoonful of bees', 'search.tracks.position' => 1 });
+  my $req = GET( $uri, 'Accept' => 'text/x-json' );
+  $mech->request($req);
+  if (cmp_ok( $mech->status, '==', 200, 'search on col which exists for me and related table okay' )) {
+    my @expected_response = map { { $_->get_columns } } $schema->resultset('CD')->search({'me.title' => 'Spoonful of bees', 'tracks.position' => 1}, { join => 'tracks' })->all;
+    my $response = JSON::Syck::Load( $mech->content);
+    #use Data::Dumper; warn Dumper($response, \@expected_response);
+    is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for search on col which exists for me and related table' );
+  }
+}




More information about the Catalyst-commits mailing list