aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-28 15:36:16 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-28 15:36:16 -0300
commit092b92f1bdddc21d92c8e60d1eb112759beb790a (patch)
tree73354cb994a50e1be3de7a0bf49d5a403e82617f /activerecord/lib
parentfcf9b712b1dbbcb8f48644e6f20676ad9480ba66 (diff)
parentc59e01a108b37ad74c9ed2e8fb022e27a9f95213 (diff)
downloadrails-092b92f1bdddc21d92c8e60d1eb112759beb790a.tar.gz
rails-092b92f1bdddc21d92c8e60d1eb112759beb790a.tar.bz2
rails-092b92f1bdddc21d92c8e60d1eb112759beb790a.zip
Merge pull request #15389 from sgrif/sg-property-inheritance
Ensure custom properties work correctly with inheritance
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/properties.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/properties.rb b/activerecord/lib/active_record/properties.rb
index 417afe6109..a51dd56bcf 100644
--- a/activerecord/lib/active_record/properties.rb
+++ b/activerecord/lib/active_record/properties.rb
@@ -4,6 +4,11 @@ module ActiveRecord
Type = ActiveRecord::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