aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-24 05:30:26 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-27 05:42:45 -0700
commit6b46106d65c749d4eba304b753f9a70ede6ed5d9 (patch)
tree6bb4c4d823b5dc30445b2ce8c6ba948a2a5a685e /activerecord/lib/active_record
parent7f1e5504ab3770aef51f55c7d32ebc699bd8947d (diff)
downloadrails-6b46106d65c749d4eba304b753f9a70ede6ed5d9.tar.gz
rails-6b46106d65c749d4eba304b753f9a70ede6ed5d9.tar.bz2
rails-6b46106d65c749d4eba304b753f9a70ede6ed5d9.zip
Deprecate decimal columns being automatically treated as integers
With ActiveRecord::Properties, we now have a reasonable path for users to continue to keep this behavior if they want it. This is an edge case that has added a lot of complexity to the code base.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/properties.rb14
3 files changed, 16 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index ca5db4095e..6ecd4efdc8 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -396,6 +396,7 @@ module ActiveRecord
precision = extract_precision(sql_type)
if scale == 0
+ # FIXME: Remove this class as well
Type::DecimalWithoutScale.new(precision: precision)
else
Type::Decimal.new(precision: precision, scale: scale)
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 1f327d1f2f..027169ae3c 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -478,6 +478,8 @@ module ActiveRecord
# places after decimal = fmod - 4 & 0xffff
# places before decimal = (fmod - 4) >> 16 & 0xffff
if fmod && (fmod - 4 & 0xffff).zero?
+ # FIXME: Remove this class, and the second argument to
+ # lookups on PG
Type::DecimalWithoutScale.new(precision: precision)
else
OID::Decimal.new(precision: precision, scale: scale)
diff --git a/activerecord/lib/active_record/properties.rb b/activerecord/lib/active_record/properties.rb
index a5d724de0e..39c39ad9ff 100644
--- a/activerecord/lib/active_record/properties.rb
+++ b/activerecord/lib/active_record/properties.rb
@@ -64,7 +64,19 @@ module ActiveRecord
# Returns an array of column objects for the table associated with this class.
def columns
- @columns ||= add_user_provided_columns(connection.schema_cache.columns(table_name))
+ @columns ||= add_user_provided_columns(connection.schema_cache.columns(table_name)).each do |column|
+ if Type::DecimalWithoutScale === column.cast_type
+ ActiveSupport::Deprecation.warn <<-MESSAGE.strip_heredoc
+ Decimal columns with 0 scale being automatically treated as integers
+ is deprecated, and will be removed in a future version of Rails. If
+ you'd like to keep this behavior, add
+
+ property :#{column.name}, Type::Integer.new
+
+ to your #{name} model.
+ MESSAGE
+ end
+ end
end
# Returns a hash of column objects for the table associated with this class.