[Groonga-commit] ranguba/groonga-client-model at 0659703 [master] Support upserting sub records

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Dec 19 17:36:33 JST 2016


Kouhei Sutou	2016-12-19 17:36:33 +0900 (Mon, 19 Dec 2016)

  New Revision: 06597031e197f317f224fd6f83763e876c4f25ab
  https://github.com/ranguba/groonga-client-model/commit/06597031e197f317f224fd6f83763e876c4f25ab

  Message:
    Support upserting sub records

  Modified files:
    lib/groonga_client_model/record.rb

  Modified: lib/groonga_client_model/record.rb (+18 -5)
===================================================================
--- lib/groonga_client_model/record.rb    2016-12-19 17:10:16 +0900 (433e006)
+++ lib/groonga_client_model/record.rb    2016-12-19 17:36:33 +0900 (8d9888f)
@@ -234,11 +234,7 @@ module GroongaClientModel
     end
 
     def upsert_raw
-      attributes.each do |name, value|
-        if value.is_a?(Record) and value.changed?
-          value.save
-        end
-      end
+      upsert_sub_records
       Client.open do |client|
         table = self.class.schema.tables[self.class.table_name]
         load_value_generator = LoadValueGenerator.new(self)
@@ -277,6 +273,23 @@ module GroongaClientModel
       end
     end
 
+    def upsert_sub_records
+      attributes.each do |name, value|
+        upsert_sub_record(value)
+      end
+    end
+
+    def upsert_sub_record(sub_record)
+      case sub_record
+      when Record
+        sub_record.save if sub_record.changed?
+      when Array
+        sub_record.each do |sub_element|
+          upsert_sub_record(sub_element)
+        end
+      end
+    end
+
     def build_sub_record(name, value)
       column = self.class.columns[name]
       return value unless column
-------------- next part --------------
HTML����������������������������...
下载 



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