Module: RESTFramework::Mixins::BulkDestroyModelMixin
- Included in:
- BulkModelControllerMixin
- Defined in:
- lib/rest_framework/mixins/bulk_model_controller_mixin.rb
Overview
Mixin for destroying records in bulk.
Instance Method Summary collapse
- #destroy_all ⇒ Object
-
#destroy_all! ⇒ Object
Perform the ‘destroy!` call and return the destroyed (and frozen) record.
Instance Method Details
#destroy_all ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rest_framework/mixins/bulk_model_controller_mixin.rb', line 61 def destroy_all if params[:_json].is_a?(Array) records = self.destroy_all! serialized_records = self.bulk_serialize(records) return api_response(serialized_records) end return api_response( {message: "Bulk destroy requires an array of primary keys as input."}, status: 400, ) end |
#destroy_all! ⇒ Object
Perform the ‘destroy!` call and return the destroyed (and frozen) record.
75 76 77 78 79 80 81 82 83 |
# File 'lib/rest_framework/mixins/bulk_model_controller_mixin.rb', line 75 def destroy_all! pk = self.class.get_model.primary_key destroy_data = self.request.request_parameters[:_json] # Perform bulk destroy in a transaction. return ActiveRecord::Base.transaction do next self.get_recordset.where(pk => destroy_data).destroy_all end end |