Method: WeaviateRecord::Base#destroy

Defined in:
lib/weaviate_record/base.rb

#destroyObject

Destroys the record in the weaviate database. Returns true if the record is destroyed successfully. Otherwise, it returns false. If the record is the original record with valid id, it freezes the existing record object. If the record does not have a valid id, it converts all the attributes to nil.

Example:

article = Article.new(title: 'Hello World', content: 'This is the content of the article')

article.destroy # => false
article.title   # => nil

article.title = 'New title'
article.save

article.destroy # => true

article.frozen? # => true


215
216
217
218
219
220
221
222
223
# File 'lib/weaviate_record/base.rb', line 215

def destroy
  return self unless validate_record_for_destroy

  result = @connection.delete_call(@meta_attributes['id'])
  return freeze if result == true

  errors.add(:base, message: result['error']) if result['error'].present?
  false
end