def delete_all(self, collection_id, parent_id, filters=None, with_deleted=True, id_field=DEFAULT_ID_FIELD, modified_field=DEFAULT_MODIFIED_FIELD, deleted_field=DEFAULT_DELETED_FIELD, auth=None): """Delete all objects in this `collection_id` for this `parent_id`. :param str collection_id: the collection id. :param str parent_id: the collection parent. :param filters: Optionnally filter the objects to delete. :type filters: list of :class:`cliquet.storage.Filter` :param bool with_deleted: track deleted records with a tombstone :returns: the list of deleted objects, with minimal set of attributes. :rtype: list of dict """ qry = Session.query(self.collection).options(load_only('id'))\ .filter(and_(self.collection.parent_id == parent_id, getattr(self.collection, deleted_field) == False)) for every in filters: qry = qry.filter(SQLAFilter(self.collection, every)()) rows = [{"id": every.id, "parent_id": parent_id, "collection_id": collection_id, modified_field: datetime.datetime.utcnow()} for every in qry.all()] Session.bulk_update_mappings(self.collection, [{"id": every['id'], deleted_field: True, modified_field: every[modified_field]} for every in rows]) if with_deleted: Session.bulk_insert_mappings(Deleted, rows) return rows