Skip to content
This repository
Browse code

Merge [5401] from trunk.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5402 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 31b901aa655524131285b1bcf9b5f256f0426ae9 1 parent a746e39
Jeremy Kemper jeremy authored
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *SVN*
2 2
  3 +* has_one :dependent => :nullify ignores nil associates. #6528 [janovetz, Jeremy Kemper]
  4 +
3 5 * 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]
4 6
5 7 * Make add_column use the options hash with the Sqlite Adapter. Closes #6464 [obrie]
2  activerecord/lib/active_record/associations.rb
@@ -1060,7 +1060,7 @@ def configure_dependency_for_has_one(reflection)
1060 1060 when :delete
1061 1061 module_eval "before_destroy '#{reflection.class_name}.delete(#{reflection.name}.id) unless #{reflection.name}.nil?'"
1062 1062 when :nullify
1063   - module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil)'"
  1063 + module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil) unless #{reflection.name}.nil?'"
1064 1064 when nil, false
1065 1065 # pass
1066 1066 else
12 activerecord/test/associations_test.rb
@@ -184,11 +184,13 @@ def test_assignment_without_replacement_on_create
184 184
185 185 def test_dependence
186 186 num_accounts = Account.count
  187 +
187 188 firm = Firm.find(1)
188 189 assert !firm.account.nil?
189 190 account_id = firm.account.id
190 191 assert_equal [], Account.destroyed_account_ids[firm.id]
191   - firm.destroy
  192 +
  193 + firm.destroy
192 194 assert_equal num_accounts - 1, Account.count
193 195 assert_equal [account_id], Account.destroyed_account_ids[firm.id]
194 196 end
@@ -201,15 +203,23 @@ def test_deprecated_exclusive_dependence
201 203
202 204 def test_exclusive_dependence
203 205 num_accounts = Account.count
  206 +
204 207 firm = ExclusivelyDependentFirm.find(9)
205 208 assert !firm.account.nil?
206 209 account_id = firm.account.id
207 210 assert_equal [], Account.destroyed_account_ids[firm.id]
  211 +
208 212 firm.destroy
209 213 assert_equal num_accounts - 1, Account.count
210 214 assert_equal [], Account.destroyed_account_ids[firm.id]
211 215 end
212 216
  217 + def test_dependence_with_nil_associate
  218 + firm = DependentFirm.new(:name => 'nullify')
  219 + firm.save!
  220 + assert_nothing_raised { firm.destroy }
  221 + end
  222 +
213 223 def test_succesful_build_association
214 224 firm = Firm.new("name" => "GlobalMegaCorp")
215 225 firm.save

0 comments on commit 31b901a

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