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