[Groonga-commit] ranguba/groonga-client-model at 26d09c4 [master] Support loading _id on save

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Dec 5 18:15:47 JST 2016


Kouhei Sutou	2016-12-05 18:15:47 +0900 (Mon, 05 Dec 2016)

  New Revision: 26d09c47fe541bb097c051103b7a8c59884c4346
  https://github.com/ranguba/groonga-client-model/commit/26d09c47fe541bb097c051103b7a8c59884c4346

  Message:
    Support loading _id on save
    
    It's just workaround. We need Groonga level support.

  Modified files:
    lib/groonga_client_model/record.rb

  Modified: lib/groonga_client_model/record.rb (+18 -1)
===================================================================
--- lib/groonga_client_model/record.rb    2016-12-05 18:15:31 +0900 (1bf50c4)
+++ lib/groonga_client_model/record.rb    2016-12-05 18:15:47 +0900 (7b6db65)
@@ -167,7 +167,8 @@ module GroongaClientModel
     private
     def upsert
       Client.open do |client|
-        response = client.load(table: self.class.table_name,
+        table = self.class.schema.tables[self.class.table_name]
+        response = client.load(table: table.name,
                                values: [attributes])
         unless response.success?
           message = "Failed to save: "
@@ -178,6 +179,22 @@ module GroongaClientModel
           message = "Failed to save: #{self.inspect}"
           raise RecordNotSaved.new(message, self)
         end
+        if @new_record
+          if****@attri*****?("_key")
+            select_response = client.select(table: table.name,
+                                            # TODO: #{_key} is dangerous
+                                            filter: "_key == #{_key}",
+                                            limit: 1,
+                                            output_columns: "_id")
+          else
+            select_response = client.select(table: table.name,
+                                            limit: 1,
+                                            output_columns: "_id",
+                                            # TODO: may return not newly added record
+                                            sort_keys: "-_id")
+          end
+          self._id = select_response.records.first["_id"]
+        end
         @new_record = false
         true
       end
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index