aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-29 19:19:08 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-03-29 19:19:08 -0700
commit130064d5049cb6df4d0c14964c253d3bad26e001 (patch)
tree432a6a4515ba6c74509f4ae55fa5aa432d0536cb /activerecord/lib/active_record
parent648248bbb13aa5259b1e64d9a8376cdbe6717e37 (diff)
parentf50c160cd028bd3e16c46dcba7692439daf709c8 (diff)
downloadrails-130064d5049cb6df4d0c14964c253d3bad26e001.tar.gz
rails-130064d5049cb6df4d0c14964c253d3bad26e001.tar.bz2
rails-130064d5049cb6df4d0c14964c253d3bad26e001.zip
Merge pull request #5661 from carlosantoniodasilva/ar-pk-typecast
Typecast 'id' attribute in read_attribute when using custom pks
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb5
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb4
2 files changed, 8 insertions, 1 deletions
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
}
}
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