aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 6eb1d907e6..0319781e03 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -15,6 +15,10 @@ module ActiveRecord
@loaded, @readonly = false
end
+ def new(*args, &block)
+ @klass.send(:with_scope, :create => create_scope) { @klass.new(*args, &block) }
+ end
+
def merge(r)
raise ArgumentError, "Cannot merge a #{r.klass.name} relation with #{@klass.name} relation" if r.klass != @klass
@@ -138,7 +142,7 @@ module ActiveRecord
end
def reset
- @first = @last = nil
+ @first = @last = @create_scope = nil
@records = []
self
end
@@ -181,6 +185,13 @@ module ActiveRecord
end
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
+ end
+ end
+
def where_clause(join_string = " AND ")
@relation.send(:where_clauses).join(join_string)
end