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
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rest_framework/mixins/bulk_model_controller_mixin.rb', line 67 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.
81 82 83 84 85 86 87 88 89 |
# File 'lib/rest_framework/mixins/bulk_model_controller_mixin.rb', line 81 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 |