From c59e01a108b37ad74c9ed2e8fb022e27a9f95213 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 28 May 2014 10:11:57 -0700 Subject: Ensure custom properties work correctly with inheritance --- activerecord/lib/active_record/properties.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/properties.rb b/activerecord/lib/active_record/properties.rb index a25c1cec58..aee1116511 100644 --- a/activerecord/lib/active_record/properties.rb +++ b/activerecord/lib/active_record/properties.rb @@ -4,6 +4,11 @@ module ActiveRecord Type = ConnectionAdapters::Type + included do + class_attribute :user_provided_columns, instance_accessor: false # :internal + self.user_provided_columns = {} + end + module ClassMethods # Defines or overrides a property on this model. This allows customization of # Active Record's type casting behavior, as well as adding support for user defined @@ -59,7 +64,8 @@ module ActiveRecord # store_listing.price_in_cents # => 1000 def property(name, cast_type) name = name.to_s - user_provided_columns[name] = ConnectionAdapters::Column.new(name, nil, cast_type) + # Assign a new hash to ensure that subclasses do not share a hash + self.user_provided_columns = user_provided_columns.merge(name => ConnectionAdapters::Column.new(name, nil, cast_type)) end # Returns an array of column objects for the table associated with this class. @@ -81,10 +87,6 @@ module ActiveRecord private - def user_provided_columns - @user_provided_columns ||= {} - end - def add_user_provided_columns(schema_columns) schema_columns.reject { |column| user_provided_columns.key? column.name -- cgit v1.2.3