diff options
Diffstat (limited to 'activerecord/lib/active_record/attribute_set.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_set.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index f545fa8a9a..99fc9b6ac6 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -10,9 +10,10 @@ module ActiveRecord attributes.each_with_object({}) { |(k, v), h| h[k] = v.value_before_type_cast } end - def update(other) - attributes.update(other.attributes) + def to_hash + attributes.each_with_object({}) { |(k, v), h| h[k] = v.value } end + alias_method :to_h, :to_hash def freeze @attributes.freeze @@ -33,13 +34,14 @@ module ActiveRecord super end - class Builder + class Builder # :nodoc: def initialize(types) @types = types end def build_from_database(values, additional_types = {}) - attributes = values.each_with_object({}) do |(name, value), hash| + attributes = Hash.new(Attribute::Null) + values.each_with_object(attributes) do |(name, value), hash| type = additional_types.fetch(name, @types[name]) hash[name] = Attribute.from_database(value, type) end @@ -50,6 +52,5 @@ module ActiveRecord protected attr_reader :attributes - end end |