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
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rest_framework/mixins/bulk_model_controller_mixin.rb', line 57 def destroy_all if params[:_json].is_a?(Array) records = self.destroy_all! serialized_records = self.bulk_serialize(records) return render(api: serialized_records) end render( api: { 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.
70 71 72 73 74 75 76 |
# File 'lib/rest_framework/mixins/bulk_model_controller_mixin.rb', line 70 def destroy_all! pk = self.class.get_model.primary_key destroy_data = self.request.request_parameters[:_json] # Perform bulk destroy in a transaction. ActiveRecord::Base.transaction { self.get_recordset.where(pk => destroy_data).destroy_all } end |