Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/mark_only.rb
Instance Method Summary collapse
- #delete_all(*args, &block) ⇒ Object
- #destroy_all(*args, &block) ⇒ Object
-
#mark_only_orig_relation_delete_all ⇒ Object
don’t use generic naming to try to avoid conflicts, since this isn’t model class specific.
-
#mark_only_orig_relation_destroy_all ⇒ Object
don’t use generic naming to try to avoid conflicts, since this isn’t model class specific.
Instance Method Details
#delete_all(*args, &block) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mark_only.rb', line 78 def delete_all(*args, &block) return mark_only_orig_relation_delete_all(*args, &block) unless !!::MarkOnly.enabled 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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mark_only.rb', line 99 def destroy_all(*args, &block) return mark_only_orig_relation_destroy_all(*args, &block) unless !!::MarkOnly.enabled 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_all ⇒ Object
don’t use generic naming to try to avoid conflicts, since this isn’t model class specific
77 |
# File 'lib/mark_only.rb', line 77 alias_method :mark_only_orig_relation_delete_all, :delete_all |
#mark_only_orig_relation_destroy_all ⇒ Object
don’t use generic naming to try to avoid conflicts, since this isn’t model class specific
98 |
# File 'lib/mark_only.rb', line 98 alias_method :mark_only_orig_relation_destroy_all, :destroy_all |