diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-28 10:11:57 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-05-28 11:34:20 -0700 |
commit | c59e01a108b37ad74c9ed2e8fb022e27a9f95213 (patch) | |
tree | 5a5918669692dd7c2413926a7937f78e314363ba /activerecord/lib | |
parent | abd6461e2881a09cb7b719ffb016c0c85d89ffe0 (diff) | |
download | rails-c59e01a108b37ad74c9ed2e8fb022e27a9f95213.tar.gz rails-c59e01a108b37ad74c9ed2e8fb022e27a9f95213.tar.bz2 rails-c59e01a108b37ad74c9ed2e8fb022e27a9f95213.zip |
Ensure custom properties work correctly with inheritance
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/properties.rb | 12 |
1 files changed, 7 insertions, 5 deletions
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 |