Method: WeaviateRecord::Base#persisted?

Defined in:
lib/weaviate_record/base.rb

#persisted?Boolean

Checks whether the record is saved in the weaviate database or not. If the record is saved, it returns true. Otherwise, it returns false.

Example:

article = Article.new(title: 'Hello World', content: 'This is the content of the article')
article.save
article.persisted? # => true

Returns:

  • (Boolean)


232
233
234
235
236
237
238
239
# File 'lib/weaviate_record/base.rb', line 232

def persisted?
  if @custom_selected || !respond_to?(:id)
    raise WeaviateRecord::Errors::CustomQueriedRecordError,
          'cannot perform persisted? action on custom queried record'
  end

  id.present?
end