Skip to content
Browse files

Fix situation where id method didn't get defined causing postgres to …

  • Loading branch information...
1 parent a51c4a3 commit 4d8ee28841261827c22322e769cb00c4f4fdc3e6 @jonleighton jonleighton committed Dec 23, 2011
Showing with 3 additions and 4 deletions.
  1. +3 −4 activerecord/lib/active_record/attribute_methods.rb
7 activerecord/lib/active_record/attribute_methods.rb
@@ -64,7 +64,9 @@ def instance_method_already_implemented?(method_name)
if superclass == Base
- method_defined_within?(method_name, superclass, superclass.generated_attribute_methods) || super
+ # If B < A and A defines its own attribute method, then we don't want to overwrite that.
+ defined = method_defined_within?(method_name, superclass, superclass.generated_attribute_methods)
+ defined && !ActiveRecord::Base.method_defined?(method_name) || super
@@ -74,9 +76,6 @@ def dangerous_attribute_method?(name)
method_defined_within?(name, Base)
- # Note that we could do this via klass.instance_methods(false), but this would require us
- # to maintain a cached Set (for speed) and invalidate it at the correct time, which would
- # be a pain. This implementation is also O(1) while avoiding maintaining a cached Set.
def method_defined_within?(name, klass, sup = klass.superclass)
if klass.method_defined?(name) || klass.private_method_defined?(name)
if sup.method_defined?(name) || sup.private_method_defined?(name)

2 comments on commit 4d8ee28

Ruby on Rails member

@jonleighton Do you remember what is this for? I suspect it's the same problem I'm trying to fix in #14052, but it'd be great to have you c/d this before that is merged.

Ruby on Rails member

@chancancode no idea sorry. by the commit message it sounds like I was trying to fix a build failure. but really I can't remember at all.

Please sign in to comment.
Something went wrong with that request. Please try again.