aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-30 13:55:56 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-30 13:55:56 -0300
commitce348b9b213f339eaac13d4c86bd3f5648e60ef4 (patch)
treea323e01e318542b9da50d96031572d43857eb2df /activerecord/lib/active_record
parent8c7a44ebef0f7cf972bc91127f83b7bad1b60135 (diff)
parent5aa1f5d39987e176631fa9119d12e0aaabf98787 (diff)
downloadrails-ce348b9b213f339eaac13d4c86bd3f5648e60ef4.tar.gz
rails-ce348b9b213f339eaac13d4c86bd3f5648e60ef4.tar.bz2
rails-ce348b9b213f339eaac13d4c86bd3f5648e60ef4.zip
Merge pull request #15354 from sgrif/sg-properties-default
Allow specifying a default value in overloaded properties
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/properties.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/properties.rb b/activerecord/lib/active_record/properties.rb
index 7fe59ccce4..21ff906fec 100644
--- a/activerecord/lib/active_record/properties.rb
+++ b/activerecord/lib/active_record/properties.rb
@@ -14,6 +14,17 @@ module ActiveRecord
# Active Record's type casting behavior, as well as adding support for user defined
# types.
#
+ # +name+ The name of the methods to define attribute methods for, and the column which
+ # this will persist to.
+ #
+ # +cast_type+ A type object that contains information about how to type cast the value.
+ # See the examples section for more information.
+ #
+ # ==== Options
+ # The options hash accepts the following options:
+ #
+ # +default+ is the default value that the column should use on a new record.
+ #
# ==== Examples
#
# The type detected by Active Record can be overriden.
@@ -62,11 +73,11 @@ module ActiveRecord
#
# store_listing = StoreListing.new(price_in_cents: '$10.00')
# store_listing.price_in_cents # => 1000
- def property(name, cast_type)
+ def property(name, cast_type, options = {})
name = name.to_s
clear_properties_cache
# Assign a new hash to ensure that subclasses do not share a hash
- self.user_provided_columns = user_provided_columns.merge(name => connection.new_column(name, nil, cast_type))
+ self.user_provided_columns = user_provided_columns.merge(name => connection.new_column(name, options[:default], cast_type))
end
# Returns an array of column objects for the table associated with this class.