diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-23 20:31:24 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-23 21:12:37 +0000 |
commit | 0a2e37975d15310fab01b55a1e3858f137dcd685 (patch) | |
tree | 74d9841348e7bc35af06a94d82f8d3acd6dcd2f5 /activerecord/lib/active_record/attribute_methods.rb | |
parent | 4a86708e2947b0fdd9a5fa8da03c69c8fc528ade (diff) | |
download | rails-0a2e37975d15310fab01b55a1e3858f137dcd685.tar.gz rails-0a2e37975d15310fab01b55a1e3858f137dcd685.tar.bz2 rails-0a2e37975d15310fab01b55a1e3858f137dcd685.zip |
Fix situation where id method didn't get defined causing postgres to fail
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 20cb98f033..883440542d 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -65,7 +65,9 @@ module ActiveRecord if superclass == Base super else - 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 end end @@ -75,9 +77,6 @@ module ActiveRecord method_defined_within?(name, Base) end - # 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) |