Class: ActiveRecord::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/mark_only.rb

Instance Method Summary collapse

Instance Method Details

#delete_all(*args, &block) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/mark_only.rb', line 71

def delete_all(*args, &block)
  if klass.respond_to?(:mark_only?) && klass.mark_only?
    logger.debug("will not #{self}.delete_all", e) if MarkOnly.debug
    if args.length > 0 && block_given?
      where(*args, &block)
    elsif args.length > 0 && !block_given?
      where(*args)
    elsif args.length == 0 && block_given?
      where(&block)
    end
    c = "#{quoted_table_name}.#{connection.quote_column_name self.mark_only_column}"
    where("#{c} != ? OR #{c} IS NULL", MarkOnly.deleted_value)
    update_all({self.mark_only_column => MarkOnly.deleted_value})
  else
    mark_only_orig_relation_delete_all(*args, &block)
  end
end

#destroy_all(*args, &block) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mark_only.rb', line 91

def destroy_all(*args, &block)
  if klass.respond_to?(:mark_only?) && klass.mark_only?
    logger.debug("will not #{self}.destroy_all", e) if MarkOnly.debug
    if args.length > 0 && block_given?
      where(*args, &block)
    elsif args.length > 0 && !block_given?
      where(*args)
    elsif args.length == 0 && block_given?
      where(&block)
    end
    c = "#{quoted_table_name}.#{connection.quote_column_name self.mark_only_column}"
    where("#{c} != ? OR #{c} IS NULL", MarkOnly.deleted_value)
    update_all({self.mark_only_column => MarkOnly.deleted_value})
    #rel.to_a.each {|object| object.run_callbacks(:destroy) { delete }}.tap { reset }
  else
    mark_only_orig_relation_destroy_all(*args, &block)
  end
end

#mark_only_orig_relation_delete_allObject

don’t use generic naming to try to avoid conflicts, since this isn’t model class specific



70
# File 'lib/mark_only.rb', line 70

alias_method :mark_only_orig_relation_delete_all, :delete_all

#mark_only_orig_relation_destroy_allObject

don’t use generic naming to try to avoid conflicts, since this isn’t model class specific



90
# File 'lib/mark_only.rb', line 90

alias_method :mark_only_orig_relation_destroy_all, :destroy_all