aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-06-06 11:56:12 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-06-07 11:11:08 +0900
commit9b8c7796a9c2048208aa843ad3dc477dffa8bdee (patch)
tree1ab85743b084a1f315396e80025be467654499a9 /activerecord/lib
parent2b96d5822bfe407be7589e293f3265c0c7a6726c (diff)
downloadrails-9b8c7796a9c2048208aa843ad3dc477dffa8bdee.tar.gz
rails-9b8c7796a9c2048208aa843ad3dc477dffa8bdee.tar.bz2
rails-9b8c7796a9c2048208aa843ad3dc477dffa8bdee.zip
Avoid overwriting the methods of `AttributeMethods::PrimaryKey`
Currently the methods of `AttributeMethods::PrimaryKey` are overwritten by `define_attribute_methods`. It will be broken if a table that customized primary key has non primary key id column. It should not be overwritten if a table has any primary key. Fixes #29350.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb10
1 files changed, 3 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index 2f32caa257..b5fd0cb370 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -57,16 +57,12 @@ module ActiveRecord
end
module ClassMethods
- def define_method_attribute(attr_name)
- super
+ ID_ATTRIBUTE_METHODS = %w(id id= id? id_before_type_cast id_was id_in_database).to_set
- if attr_name == primary_key && attr_name != "id"
- generated_attribute_methods.send(:alias_method, :id, primary_key)
- end
+ def instance_method_already_implemented?(method_name)
+ super || primary_key && ID_ATTRIBUTE_METHODS.include?(method_name)
end
- ID_ATTRIBUTE_METHODS = %w(id id= id? id_before_type_cast id_was id_in_database).to_set
-
def dangerous_attribute_method?(method_name)
super && !ID_ATTRIBUTE_METHODS.include?(method_name)
end