Module: Discard::Model::ClassMethods
- Defined in:
- lib/discard/model.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#discard_all ⇒ Object
Discards the records by instantiating each record and calling its #discard method.
-
#discard_all! ⇒ Object
Discards the records by instantiating each record and calling its #discard! method.
-
#undiscard_all ⇒ Object
Undiscards the records by instantiating each record and calling its #undiscard method.
-
#undiscard_all! ⇒ Object
Undiscards the records by instantiating each record and calling its #undiscard! method.
Instance Method Details
#discard_all ⇒ Object
Discards the records by instantiating each record and calling its Discard::Model#discard method. Each object’s callbacks are executed. Returns the collection of objects that were discarded.
Note: Instantiation, callback execution, and update of each record can be time consuming when you’re discarding many records at once. It generates at least one SQL UPDATE
query per record (or possibly more, to enforce your callbacks). If you want to discard many rows quickly, without concern for their associations or callbacks, use #update_all(discarded_at: Time.current) instead.
Examples
Person.where(age: 0..18).discard_all
42 43 44 |
# File 'lib/discard/model.rb', line 42 def discard_all kept.each(&:discard) end |
#discard_all! ⇒ Object
Discards the records by instantiating each record and calling its Discard::Model#discard! method. Each object’s callbacks are executed. Returns the collection of objects that were discarded.
Note: Instantiation, callback execution, and update of each record can be time consuming when you’re discarding many records at once. It generates at least one SQL UPDATE
query per record (or possibly more, to enforce your callbacks). If you want to discard many rows quickly, without concern for their associations or callbacks, use #update_all!(discarded_at: Time.current) instead.
Examples
Person.where(age: 0..18).discard_all!
61 62 63 |
# File 'lib/discard/model.rb', line 61 def discard_all! kept.each(&:discard!) end |
#undiscard_all ⇒ Object
Undiscards the records by instantiating each record and calling its Discard::Model#undiscard method. Each object’s callbacks are executed. Returns the collection of objects that were undiscarded.
Note: Instantiation, callback execution, and update of each record can be time consuming when you’re undiscarding many records at once. It generates at least one SQL UPDATE
query per record (or possibly more, to enforce your callbacks). If you want to undiscard many rows quickly, without concern for their associations or callbacks, use #update_all(discarded_at: nil) instead.
Examples
Person.where(age: 0..18).undiscard_all
80 81 82 |
# File 'lib/discard/model.rb', line 80 def undiscard_all discarded.each(&:undiscard) end |
#undiscard_all! ⇒ Object
Undiscards the records by instantiating each record and calling its Discard::Model#undiscard! method. Each object’s callbacks are executed. Returns the collection of objects that were undiscarded.
Note: Instantiation, callback execution, and update of each record can be time consuming when you’re undiscarding many records at once. It generates at least one SQL UPDATE
query per record (or possibly more, to enforce your callbacks). If you want to undiscard many rows quickly, without concern for their associations or callbacks, use #update_all!(discarded_at: nil) instead.
Examples
Person.where(age: 0..18).undiscard_all!
99 100 101 |
# File 'lib/discard/model.rb', line 99 def undiscard_all! discarded.each(&:undiscard!) end |