[Catalyst-commits] r9172 - in Catalyst-Controller-DBIC-API/1.001/trunk: lib/Catalyst/Controller/DBIC/API t/rpc t/var

lukes at dev.catalyst.perl.org lukes at dev.catalyst.perl.org
Mon Feb 2 22:42:47 GMT 2009


Author: lukes
Date: 2009-02-02 22:42:46 +0000 (Mon, 02 Feb 2009)
New Revision: 9172

Modified:
   Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
   Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t
   Catalyst-Controller-DBIC-API/1.001/trunk/t/var/DBIxClass.db
Log:
fixed error case where col and rel have the same name

Modified: Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2009-02-02 22:42:33 UTC (rev 9171)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2009-02-02 22:42:46 UTC (rev 9172)
@@ -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');
 }
 
@@ -46,7 +44,6 @@
   my ($self, $c) = @_;
 
   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 ) {
@@ -55,7 +52,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);
@@ -74,20 +70,25 @@
 	my ($self, $p) = @_;
 	my $params = $p->{params};
 	my $source = $p->{source};
-	my $base = $p->{base};
+	my $base = $p->{base} || 'me';
 
 	my $join = {};
-	my %search_params = map { ($base) ? join('.', $base, $_) : $_ => $params->{$_} } grep { exists $params->{$_} } $source->columns;
-	foreach my $rel ($source->relationships) {
-		# if column and relationship have the same name, go with the relationship
-		# so long as the value is a reference, otherwise go with the column
-		if (my $val = $search_params{$rel}) {
- 	 	 	if (ref $val) {
- 	 	 	 	delete $search_params{$rel};
- 	 	 	} else {
- 	 	 	 	next;
- 	 	 	}
-		}
+  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});
+
+    $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
 		if (exists $params->{$rel}) {
 			my $rel_params;
 			($rel_params, $join->{$rel}) = $self->_format_search({ params => $params->{$rel}, source => $source->related_source($rel), base => $rel });
@@ -175,7 +176,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/trunk/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t	2009-02-02 22:42:33 UTC (rev 9171)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t	2009-02-02 22:42:46 UTC (rev 9172)
@@ -151,14 +151,13 @@
   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})->all;
+    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' );

Modified: Catalyst-Controller-DBIC-API/1.001/trunk/t/var/DBIxClass.db
===================================================================
(Binary files differ)




More information about the Catalyst-commits mailing list