aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-03 23:48:53 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-03 16:24:32 -0800
commit40afcade0dc1450e765a91fc15a6ac6d442c9826 (patch)
tree4d205b197a761fcd8b74854ebf4cc0139277a280 /activerecord/lib/active_record/associations.rb
parent2120da7f733ba33183a42e71256db9652c5f5fcc (diff)
downloadrails-40afcade0dc1450e765a91fc15a6ac6d442c9826.tar.gz
rails-40afcade0dc1450e765a91fc15a6ac6d442c9826.tar.bz2
rails-40afcade0dc1450e765a91fc15a6ac6d442c9826.zip
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)
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r--activerecord/lib/active_record/associations.rb11
1 files changed, 3 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index e7d3e45da2..bbf96f52ed 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1556,20 +1556,15 @@ module ActiveRecord
def association_constructor_method(constructor, reflection, association_proxy_class)
redefine_method("#{constructor}_#{reflection.name}") do |*params|
- attributees = params.first unless params.empty?
- replace_existing = params[1].nil? ? true : params[1]
- association = association_instance_get(reflection.name)
+ attributes = params.first unless params.empty?
+ association = association_instance_get(reflection.name)
unless association
association = association_proxy_class.new(self, reflection)
association_instance_set(reflection.name, association)
end
- if association_proxy_class == HasOneAssociation
- association.send(constructor, attributees, replace_existing)
- else
- association.send(constructor, attributees)
- end
+ association.send(constructor, attributes)
end
end