From 77a0fc1c7a7681bae6d1956cadcb8b3ef9428896 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 29 Mar 2012 21:23:34 -0300 Subject: Properly typecast id attribute when using custom primary key --- activerecord/lib/active_record/attribute_methods/read.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index faed703167..d108de385f 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -67,7 +67,10 @@ module ActiveRecord @attributes_cache.fetch(attr_name.to_s) { |name| column = @columns_hash.fetch(name) { return @attributes.fetch(name) { - @attributes[self.class.primary_key] if name == 'id' + if name == 'id' + primary_key = self.class.primary_key + @columns_hash[primary_key].type_cast(@attributes[primary_key]) + end } } -- cgit v1.2.3 From f50c160cd028bd3e16c46dcba7692439daf709c8 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 29 Mar 2012 21:12:23 -0300 Subject: Deprecate Column#type_cast_code --- activerecord/lib/active_record/connection_adapters/column.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 78e54c4c9b..b7e1513422 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -1,4 +1,5 @@ require 'set' +require 'active_support/deprecation' module ActiveRecord # :stopdoc: @@ -107,6 +108,9 @@ module ActiveRecord end def type_cast_code(var_name) + ActiveSupport::Deprecation.warn("Column#type_cast_code is deprecated in favor of" \ + "using Column#type_cast only, and it is going to be removed in future Rails versions.") + klass = self.class.name case type -- cgit v1.2.3