Skip to content

Commit

Permalink
Merge [5401] from trunk.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5402 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Nov 2, 2006
1 parent a746e39 commit 31b901a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* has_one :dependent => :nullify ignores nil associates. #6528 [janovetz, Jeremy Kemper]

* Oracle: resolve test failures, use prefetched primary key for inserts, check for null defaults. Factor out some common methods from all adapters. #6515 [Michael Schoen]

* Make add_column use the options hash with the Sqlite Adapter. Closes #6464 [obrie]
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ def configure_dependency_for_has_one(reflection)
when :delete
module_eval "before_destroy '#{reflection.class_name}.delete(#{reflection.name}.id) unless #{reflection.name}.nil?'"
when :nullify
module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil)'"
module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil) unless #{reflection.name}.nil?'"
when nil, false
# pass
else
Expand Down
12 changes: 11 additions & 1 deletion activerecord/test/associations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ def test_assignment_without_replacement_on_create

def test_dependence
num_accounts = Account.count

firm = Firm.find(1)
assert !firm.account.nil?
account_id = firm.account.id
assert_equal [], Account.destroyed_account_ids[firm.id]
firm.destroy

firm.destroy
assert_equal num_accounts - 1, Account.count
assert_equal [account_id], Account.destroyed_account_ids[firm.id]
end
Expand All @@ -201,15 +203,23 @@ def test_deprecated_exclusive_dependence

def test_exclusive_dependence
num_accounts = Account.count

firm = ExclusivelyDependentFirm.find(9)
assert !firm.account.nil?
account_id = firm.account.id
assert_equal [], Account.destroyed_account_ids[firm.id]

firm.destroy
assert_equal num_accounts - 1, Account.count
assert_equal [], Account.destroyed_account_ids[firm.id]
end

def test_dependence_with_nil_associate
firm = DependentFirm.new(:name => 'nullify')
firm.save!
assert_nothing_raised { firm.destroy }
end

def test_succesful_build_association
firm = Firm.new("name" => "GlobalMegaCorp")
firm.save
Expand Down

0 comments on commit 31b901a

Please sign in to comment.