diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 78c580fd7c6ba..7ca7a96ab7443 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2716,7 +2716,7 @@ def toggle!(attribute) def reload(options = nil) clear_aggregation_cache clear_association_cache - @attributes.update(self.class.find(self.id, options).instance_variable_get('@attributes')) + @attributes.update(self.class.send(:with_exclusive_scope) { self.class.find(self.id, options) }.instance_variable_get('@attributes')) @attributes_cache = {} self end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 6f7a77927d031..2bf7939e964d2 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1645,6 +1645,12 @@ def test_reload assert_equal t1.title, t2.title end + def test_reload_with_exclusive_scope + dev = DeveloperCalledDavid.first + dev.update_attributes!( :name => "NotDavid" ) + assert_equal dev, dev.reload + end + def test_define_attr_method_with_value k = Class.new( ActiveRecord::Base ) k.send(:define_attr_method, :table_name, "foo")