aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations/writes/delete.rb
blob: 0a04454e7f648f78054fc95e21ae52d7c994158e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Arel
  class Deletion < Compound
    attributes :relation
    deriving :initialize, :==

    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
      engine.delete(self)
    end
  end
end