@@ -5,6 +5,13 @@ module Behavior
55 extend ActiveSupport ::Concern
66
77 module ClassMethods
8+ def typed_store_attribute_names
9+ typed_stores . keys . map do |name |
10+ name = name . to_s
11+ attribute_aliases [ name ] || name
12+ end
13+ end
14+
815 def define_attribute_methods
916 super
1017 define_typed_store_attribute_methods
@@ -78,16 +85,16 @@ def attribute_names_for_partial_inserts
7885 # Contrary to all vanilla Rails types, typedstore attribute have an inherent default
7986 # value that doesn't match the database column default.
8087 # As such we need to insert them on partial inserts even if they weren't changed.
81- super | self . class . typed_stores . keys . map ( & :to_s )
88+ super | self . class . typed_store_attribute_names
8289 end
8390
8491 def attribute_names_for_partial_updates
8592 # On partial updates we shouldn't need to force stores to be persisted. However since
8693 # we weren't persisting them for a while on insertion, we now need to gracefully deal
8794 # with existing records that may have been persisted with a `NULL` store
8895 # We use `blank?` as an heuristic to detect these.
89- super | self . class . typed_stores . keys . map ( & :to_s ) . select do |store |
90- @attributes . key? ( store ) && @attributes [ store ] . value_before_type_cast . blank?
96+ super | self . class . typed_store_attribute_names . select do |store |
97+ read_attribute_before_type_cast ( store ) . blank?
9198 end
9299 end
93100 end
0 commit comments