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.rb | |
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.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index ec8ae21726..487b54f27d 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -6,7 +6,7 @@ module ActiveRecord attr_reader :relation, :klass attr_writer :readonly, :table - attr_accessor :preload_associations, :eager_load_associations, :includes_associations + attr_accessor :preload_associations, :eager_load_associations, :includes_associations, :create_with_attributes def initialize(klass, relation) @klass, @relation = klass, relation @@ -124,13 +124,13 @@ module ActiveRecord end def reset - @first = @last = @create_scope = @to_sql = @order_clause = nil + @first = @last = @to_sql = @order_clause = @scope_for_create = nil @records = [] self end def table - @table ||= Arel::Table.new(@klass.table_name, Arel::Sql::Engine.new(@klass)) + @table ||= Arel::Table.new(@klass.table_name, :engine => @klass.active_relation_engine) end def primary_key @@ -163,13 +163,15 @@ module ActiveRecord end def with_create_scope - @klass.send(:with_scope, :create => create_scope) { yield } + @klass.send(:with_scope, :create => scope_for_create) { yield } end - def create_scope - @create_scope ||= wheres.inject({}) do |hash, where| - hash[where.operand1.name] = where.operand2.value if where.is_a?(Arel::Predicates::Equality) - hash + def scope_for_create + @scope_for_create ||= begin + @create_with_attributes || wheres.inject({}) do |hash, where| + hash[where.operand1.name] = where.operand2.value if where.is_a?(Arel::Predicates::Equality) + hash + end end end |