You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/13 00:22:39 UTC

[4/5] git commit: fix issue with querying specific fields instead of entire object

fix issue with querying specific fields instead of entire object


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/88f37ce6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/88f37ce6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/88f37ce6

Branch: refs/heads/usergrid-93
Commit: 88f37ce60306321b36f3cd4c9c83533c5b41d785
Parents: 6ab616b
Author: Scott Ganyo <sc...@ganyo.com>
Authored: Wed Mar 12 16:07:34 2014 -0700
Committer: Scott Ganyo <sc...@ganyo.com>
Committed: Wed Mar 12 16:07:34 2014 -0700

----------------------------------------------------------------------
 sdks/ruby-on-rails/lib/usergrid_ironhorse/query.rb | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/88f37ce6/sdks/ruby-on-rails/lib/usergrid_ironhorse/query.rb
----------------------------------------------------------------------
diff --git a/sdks/ruby-on-rails/lib/usergrid_ironhorse/query.rb b/sdks/ruby-on-rails/lib/usergrid_ironhorse/query.rb
index 6868257..f9db153 100644
--- a/sdks/ruby-on-rails/lib/usergrid_ironhorse/query.rb
+++ b/sdks/ruby-on-rails/lib/usergrid_ironhorse/query.rb
@@ -542,9 +542,9 @@ module Usergrid
           where(conditions).delete_all
         else
           pluck :uuid
-          response = run_query
-          response.entities.each {|entity| entity.delete} # todo: can this be optimized into one call?
-          response.entities.size
+          response = load
+          response.each {|entity| entity.delete} # todo: can this be optimized into one call?
+          response.size
         end
       end
 
@@ -893,7 +893,18 @@ module Usergrid
         return if loaded?
         begin
           @response = run_query
+          if (!@options[:select] or @options[:select] == '*')
             @records = @response.entities.collect {|r| @model_class.model_name.constantize.new(r.data)}
+          else # handle list
+            selects = @options[:select].split ','
+            @records = @response.entities.collect do |r|
+              data = {}
+              (0..selects.size).each do |i|
+                data[selects[i]] = r[i]
+              end
+              @model_class.model_name.constantize.new(data)
+            end
+          end
         rescue RestClient::ResourceNotFound
           @records = []
         end