Method: WeaviateRecord::Base#save
- Defined in:
- lib/weaviate_record/base.rb
#save ⇒ Object
Saves the record in the weaviate database. Returns true if the record is saved successfully. Otherwise, it returns false. If the record is not saved successfully, it adds the errors to the record. If the record is already saved, it updates the record.
Example:
class Article < WeaviateRecord::Base
validates :title, presence: true
end
article = Article.new(title: 'Hello World', content: 'This is the content of the article')
article.save # => true
article.title = 'New title'
article.save # => true
article.title # => "New title"
article = Article.new(title: '')
article.save # => false
article.errors. # => ["Title can't be blank"]
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/weaviate_record/base.rb', line 149 def save result = validate_and_save return false unless result if result['error'].present? errors.add(:base, message: result['error']) false else @meta_attributes.merge!(self.class.(result)) true end end |