From a68165833a7ba50a1e3d731afe8934d19e3ced99 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 4 Jan 2010 03:50:16 +0530 Subject: Add Relation#create_with to explictily specify create scope --- activerecord/lib/active_record/relation/spawn_methods.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/lib/active_record/relation/spawn_methods.rb') diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index a637e97155..4ecee8c634 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -6,6 +6,7 @@ module ActiveRecord relation.preload_associations = @preload_associations relation.eager_load_associations = @eager_load_associations relation.includes_associations = @includes_associations + relation.create_with_attributes = @create_with_attributes relation.table = table relation end @@ -32,6 +33,14 @@ module ActiveRecord merged_order = relation_order.present? ? relation_order : order_clause merged_relation = merged_relation.order(merged_order) + merged_relation.create_with_attributes = @create_with_attributes + + if @create_with_attributes && r.create_with_attributes + merged_relation.create_with_attributes = @create_with_attributes.merge(r.create_with_attributes) + else + merged_relation.create_with_attributes = r.create_with_attributes || @create_with_attributes + end + merged_wheres = @relation.wheres r.wheres.each do |w| @@ -56,6 +65,7 @@ module ActiveRecord end result.readonly = self.readonly unless skips.include?(:readonly) + result.create_with_attributes = @create_with_attributes unless skips.include?(:create_with) result = result.joins(@relation.joins(@relation)) unless skips.include?(:joins) result = result.group(@relation.groupings) unless skips.include?(:group) -- cgit v1.2.3