This project is archived and is in readonly mode.

Changeset [40afcade0dc1450e765a91fc15a6ac6d442c9826] by Jon Leighton

January 4th, 2011 @ 12:24 AM

Remove undocumented feature from has_one where you could pass false as the second parameter to build_assoc or create_assoc, and the existing associated object would be untouched (the foreign key would not be nullified, and it would not be deleted). If you want behaviour similar to this you can do the following things:

  • Use :dependent => :nullify (or don't specify :dependent) if you want to prevent the existing associated object from being deleted
  • Use has_many if you actually want multiple associated objects
  • Explicitly set the foreign key if, for some reason, you really need to have multiple objects associated with the same has_one. E.g.

    previous = obj.assoc obj.create_assoc previous.update_attributes(:obj_id => obj.id) https://github.com/rails/rails/commit/40afcade0dc1450e765a91fc15a6a...

Committed by Jon Leighton

  • M activerecord/lib/active_record/associations.rb
  • M activerecord/lib/active_record/associations/has_one_association.rb
  • M activerecord/test/cases/associations/has_one_associations_test.rb
  • M activerecord/test/cases/associations/inverse_associations_test.rb

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>