aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/base.rb4
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb5
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 21453f5e9a..ef4834811c 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1685,8 +1685,8 @@ MSG
if include_readonly_attributes || (!include_readonly_attributes && !self.class.readonly_attributes.include?(name))
value = read_attribute(name)
- if value && ((self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))) || value.is_a?(Hash) || value.is_a?(Array))
- value = value.to_yaml
+ if value && self.class.serialized_attributes.key?(name)
+ value = YAML.dump value
end
attrs[self.class.arel_table[name]] = value
end
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index cc3d123cea..cb1d2ae421 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -17,6 +17,11 @@ module ActiveRecord
table = finder_class.unscoped
table_name = record.class.quoted_table_name
+
+ if value && record.class.serialized_attributes.key?(attribute.to_s)
+ value = YAML.dump value
+ end
+
sql, params = mount_sql_and_params(finder_class, table_name, attribute, value)
relation = table.where(sql, *params)