aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-06-06 14:11:54 +0200
committerYves Senn <yves.senn@gmail.com>2014-06-06 14:11:54 +0200
commit485dab41c4ff7de392ffba132fbcbff49e6fe9ef (patch)
treef28e2819a4d2c8d195ea3807acafe2369ef8421d /activerecord/lib
parent8d77436f374acf06b46d1e0615b364ebd8acae8d (diff)
parentc3bd7b57e359788b26674683fb5b1518c75f6bb1 (diff)
downloadrails-485dab41c4ff7de392ffba132fbcbff49e6fe9ef.tar.gz
rails-485dab41c4ff7de392ffba132fbcbff49e6fe9ef.tar.bz2
rails-485dab41c4ff7de392ffba132fbcbff49e6fe9ef.zip
Merge pull request #15503 from sgrif/sg-json-hstore-storage
Bring type casting behavior of hstore/json in line with serialized
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb6
-rw-r--r--activerecord/lib/active_record/core.rb9
-rw-r--r--activerecord/lib/active_record/persistence.rb2
4 files changed, 7 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb
index bf680b6624..a65ca83f77 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb
@@ -8,12 +8,6 @@ module ActiveRecord
end
def type_cast_for_write(value)
- # roundtrip to ensure uniform uniform types
- # TODO: This is not an efficient solution.
- cast_value(type_cast_for_database(value))
- end
-
- def type_cast_for_database(value)
ConnectionAdapters::PostgreSQLColumn.hstore_to_string(value)
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb
index 42a5110ffd..c87422fe32 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb
@@ -8,12 +8,6 @@ module ActiveRecord
end
def type_cast_for_write(value)
- # roundtrip to ensure uniform uniform types
- # TODO: This is not an efficient solution.
- cast_value(type_cast_for_database(value))
- end
-
- def type_cast_for_database(value)
ConnectionAdapters::PostgreSQLColumn.json_to_string(value)
end
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index d6849fef2e..c996e93076 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -278,12 +278,13 @@ module ActiveRecord
# post.init_with('attributes' => { 'title' => 'hello world' })
# post.title # => 'hello world'
def init_with(coder)
- @raw_attributes = coder['attributes']
+ @raw_attributes = coder['raw_attributes']
@column_types_override = coder['column_types']
@column_types = self.class.column_types
init_internals
+ @attributes = coder['attributes'] if coder['attributes']
@new_record = coder['new_record']
self.class.define_attribute_methods
@@ -326,12 +327,13 @@ module ActiveRecord
@raw_attributes = cloned_attributes
@raw_attributes[self.class.primary_key] = nil
+ @attributes = other.clone_attributes(:read_attribute)
+ @attributes[self.class.primary_key] = nil
run_callbacks(:initialize) unless _initialize_callbacks.empty?
@aggregation_cache = {}
@association_cache = {}
- @attributes = {}
@new_record = true
@destroyed = false
@@ -352,7 +354,8 @@ module ActiveRecord
# Post.new.encode_with(coder)
# coder # => {"attributes" => {"id" => nil, ... }}
def encode_with(coder)
- coder['attributes'] = @raw_attributes
+ coder['raw_attributes'] = @raw_attributes
+ coder['attributes'] = @attributes
coder['new_record'] = new_record?
end
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 2e3bcc0956..f1f0d3e57f 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -50,7 +50,7 @@ module ActiveRecord
klass = discriminate_class_for_record(attributes)
column_types = klass.decorate_columns(column_types.dup)
klass.allocate.init_with(
- 'attributes' => attributes,
+ 'raw_attributes' => attributes,
'column_types' => column_types,
'new_record' => false,
)