diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-02-16 10:24:05 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-02-16 10:24:05 -0800 |
commit | 079e2f4ec1c299424200f59b45bb2beae08d5966 (patch) | |
tree | 3ff3d5e4528cac8b0d16f3a6f58d35228a4b5b18 /activerecord/lib | |
parent | eeae4da6ad38b14409f8c5bdf14e423af5f22a51 (diff) | |
parent | ec4759d205efaf4c7f5c2f28bd6f6b07989990d6 (diff) | |
download | rails-079e2f4ec1c299424200f59b45bb2beae08d5966.tar.gz rails-079e2f4ec1c299424200f59b45bb2beae08d5966.tar.bz2 rails-079e2f4ec1c299424200f59b45bb2beae08d5966.zip |
Merge pull request #5064 from lest/patch-1
move id_before_type_cast to PrimaryKey module
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/before_type_cast.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/primary_key.rb | 11 |
2 files changed, 11 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/before_type_cast.rb b/activerecord/lib/active_record/attribute_methods/before_type_cast.rb index bde11d0494..d4f529acbf 100644 --- a/activerecord/lib/active_record/attribute_methods/before_type_cast.rb +++ b/activerecord/lib/active_record/attribute_methods/before_type_cast.rb @@ -20,11 +20,7 @@ module ActiveRecord # Handle *_before_type_cast for method_missing. def attribute_before_type_cast(attribute_name) - if attribute_name == 'id' - read_attribute_before_type_cast(self.class.primary_key) - else - read_attribute_before_type_cast(attribute_name) - end + read_attribute_before_type_cast(attribute_name) end end end diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb index 2e1a2dc3ef..8e0b3e1402 100644 --- a/activerecord/lib/active_record/attribute_methods/primary_key.rb +++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb @@ -1,3 +1,5 @@ +require 'set' + module ActiveRecord module AttributeMethods module PrimaryKey @@ -24,6 +26,11 @@ module ActiveRecord query_attribute(self.class.primary_key) end + # Returns the primary key value before type cast + def id_before_type_cast + read_attribute_before_type_cast(self.class.primary_key) + end + protected def attribute_method?(attr_name) @@ -45,8 +52,10 @@ module ActiveRecord end end + ID_ATTRIBUTE_METHODS = %w(id id= id? id_before_type_cast).to_set + def dangerous_attribute_method?(method_name) - super && !['id', 'id=', 'id?'].include?(method_name) + super && !ID_ATTRIBUTE_METHODS.include?(method_name) end # Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the |