DynamoDB Dynomite ActiveModel Compatible
Important: These docs are for the outdated Jets 5 versions and below. For the latest Jets docs: docs.rubyonjets.com
Dynomite is ActiveModel compatible. Thanks to this, you can use things like validations an callbacks.
app/models/product.rb
class Product < ApplicationItem
fields :category,
:sku,
:name,
:price
field :stock_quantity, default: 1
validates :price, presence: true
before_save :set_sku
def set_sku
self.sku ||= SecureRandom.hex
end
end
You use the fields method to declare multiple fields. You can also use the field method to declare a single feel with options like default.
You can use things like validates and before_save callbacks just like with ActiveRecord models because Dynomite is ActiveModel compatible.