From 1313d386dacb580858e5951418a637f4e17cf5c1 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 3 Jan 2011 10:04:40 +0000 Subject: Make Relation#create_with always merge rather than overwrite, not just when merging two relations. If you wish to overwrite, you can do relation.create_with(nil), or for a specific attribute, relation.create_with(:attr => nil). --- activerecord/lib/active_record/relation/query_methods.rb | 2 +- activerecord/lib/active_record/relation/spawn_methods.rb | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/relation') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 0ab55ae864..df09226977 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -128,7 +128,7 @@ module ActiveRecord def create_with(value) relation = clone - relation.create_with_value = value + relation.create_with_value = value && (@create_with_value || {}).merge(value) relation end diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index a8fb1bccf4..db5f1af5ca 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -53,9 +53,7 @@ module ActiveRecord merged_relation.lock_value = r.lock_value unless merged_relation.lock_value - if r.create_with_value - merged_relation.create_with_value = (merged_relation.create_with_value || {}).merge(r.create_with_value) - end + merged_relation = merged_relation.create_with(r.create_with_value) if r.create_with_value # Apply scope extension modules merged_relation.send :apply_modules, r.extensions -- cgit v1.2.3