Method: WeaviateRecord::Relation#destroy_all

Defined in:
lib/weaviate_record/relation.rb

#destroy_allObject

Deletes all the records from Weaviate matching the given conditions or search filters given in the query. This will return the result of batch delete operation given by Weaviate.

Example:

Article.where(title: nil).destroy_all
# => {"failed"=>0, "limit"=>10000, "matches"=>3, "objects"=>nil, "successful"=>3}


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/weaviate_record/relation.rb', line 57

def destroy_all
  unless @where_query
    raise WeaviateRecord::Errors::MissingWhereCondition, 'must specifiy atleast one where condition'
  end

  response = @connection.delete_where(Queries::Where.to_ruby_hash(@where_query))
  return response['results'] if response.is_a?(Hash) && response.key?('results')

  raise WeaviateRecord::Errors::ServerError,
        response == '' ? 'Unauthorized' : response.dig('error', 'message').presence
end