diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-14 14:06:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 14:06:33 -0400 |
commit | b81288541b6c8fe04082e4579e549bd71bc350dd (patch) | |
tree | a22505351281f00cc177bf68321e18fddd26f295 /activerecord/lib | |
parent | 4915bfeeea88889341153cad9166090c2d6b1910 (diff) | |
parent | 9b8c7796a9c2048208aa843ad3dc477dffa8bdee (diff) | |
download | rails-b81288541b6c8fe04082e4579e549bd71bc350dd.tar.gz rails-b81288541b6c8fe04082e4579e549bd71bc350dd.tar.bz2 rails-b81288541b6c8fe04082e4579e549bd71bc350dd.zip |
Merge pull request #29378 from kamipo/avoid_overwriting_id_attribute_methods
Avoid overwriting the methods of `AttributeMethods::PrimaryKey`
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/primary_key.rb | 10 |
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 |