Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make reset return nil when using a dangling belongs_to association. C…

…urrent behaviour is to return false which can be confusing. Closes #10293 [fcheung]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8236 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit e302759451fbed36d7e8916d7b5c8377762e3efd 1 parent 0a9bc59
Michael Koziarski NZKoz authored
2  activerecord/lib/active_record/associations/association_proxy.rb
View
@@ -46,8 +46,8 @@ def conditions
alias :sql_conditions :conditions
def reset
- @target = nil
@loaded = false
+ @target = nil
end
def reload
17 activerecord/test/associations_test.rb
View
@@ -122,6 +122,23 @@ def test_save_on_parent_saves_children
developer = Developer.create :name => "Bryan", :salary => 50_000
assert_equal 1, developer.reload.audit_logs.size
end
+
+ def test_failed_reload_returns_nil
+ p = setup_dangling_association
+ assert_nil p.author.reload
+ end
+
+ def test_failed_reset_returns_nil
+ p = setup_dangling_association
+ assert_nil p.author.reset
+ end
+
+ def setup_dangling_association
+ josh = Author.create(:name => "Josh")
+ p = Post.create(:title => "New on Edge", :body => "More cool stuff!", :author => josh)
+ josh.destroy
+ p
+ end
end
class HasOneAssociationsTest < Test::Unit::TestCase
Please sign in to comment.
Something went wrong with that request. Please try again.