diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-04 01:05:19 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-04 01:05:19 +0100 |
commit | eca11bfdb5d3cf375faf8a24e2dc0cc5abd20f92 (patch) | |
tree | d4c36dc7a14a280a948577f065132f74186f3891 /activerecord/lib/active_record/relation | |
parent | b0947bf97c0ac313799f6f1ca739b5666f5fe19f (diff) | |
parent | a68165833a7ba50a1e3d731afe8934d19e3ced99 (diff) | |
download | rails-eca11bfdb5d3cf375faf8a24e2dc0cc5abd20f92.tar.gz rails-eca11bfdb5d3cf375faf8a24e2dc0cc5abd20f92.tar.bz2 rails-eca11bfdb5d3cf375faf8a24e2dc0cc5abd20f92.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 525a9cb365..5d7bf0b7bc 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -17,6 +17,10 @@ module ActiveRecord spawn.tap {|r| r.readonly = status } end + def create_with(attributes = {}) + spawn.tap {|r| r.create_with_attributes = attributes } + end + def select(selects) if selects.present? relation = spawn(@relation.project(selects)) 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) |