aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations/deletion.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/relations/deletion.rb')
-rw-r--r--lib/arel/relations/deletion.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/arel/relations/deletion.rb b/lib/arel/relations/deletion.rb
new file mode 100644
index 0000000000..6c802ba905
--- /dev/null
+++ b/lib/arel/relations/deletion.rb
@@ -0,0 +1,25 @@
+module Arel
+ class Deletion < Writing
+ def initialize(relation)
+ @relation = relation
+ end
+
+ def to_sql(formatter = nil)
+ [
+ "DELETE",
+ "FROM #{table_sql}",
+ ("WHERE #{selects.collect(&:to_sql).join('\n\tAND ')}" unless selects.blank? ),
+ ("LIMIT #{taken}" unless taken.blank? ),
+ ].compact.join("\n")
+ end
+
+ def call(connection = engine.connection)
+ connection.delete(to_sql)
+ end
+
+ def ==(other)
+ self.class == other.class and
+ relation == other.relation
+ end
+ end
+end \ No newline at end of file