aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-03 00:16:14 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-03 00:16:14 +0530
commitac1df91e5eac4959c0030e2b2ea39968f7f9ba1a (patch)
treead99ec835442f60f25d5055e1466080bc173c8a1 /activerecord/lib/active_record/relation.rb
parent65200d2933bd337b8347dd32502a12c2fddf24f0 (diff)
downloadrails-ac1df91e5eac4959c0030e2b2ea39968f7f9ba1a.tar.gz
rails-ac1df91e5eac4959c0030e2b2ea39968f7f9ba1a.tar.bz2
rails-ac1df91e5eac4959c0030e2b2ea39968f7f9ba1a.zip
Implement Relation#create and Relation#create!
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r--activerecord/lib/active_record/relation.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 0319781e03..b445ba67b7 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -16,7 +16,15 @@ module ActiveRecord
end
def new(*args, &block)
- @klass.send(:with_scope, :create => create_scope) { @klass.new(*args, &block) }
+ with_create_scope { @klass.new(*args, &block) }
+ end
+
+ def create(*args, &block)
+ with_create_scope { @klass.create(*args, &block) }
+ end
+
+ def create!(*args, &block)
+ with_create_scope { @klass.create!(*args, &block) }
end
def merge(r)
@@ -185,6 +193,10 @@ module ActiveRecord
end
end
+ def with_create_scope
+ @klass.send(:with_scope, :create => create_scope) { 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)