Class: Dynamoid::TransactionWrite::Upsert
- Inherits:
-
UpdateUpsert
- Object
- Action
- UpdateUpsert
- Dynamoid::TransactionWrite::Upsert
- Defined in:
- lib/dynamoid/transaction_write/upsert.rb
Constant Summary
Constants inherited from Action
Instance Attribute Summary
Attributes inherited from Action
#additions, #attributes, #deletions, #model, #options, #removals
Instance Method Summary collapse
-
#initialize(model_or_model_class, attributes, options = {}) ⇒ Upsert
constructor
Upsert is just like Update buts skips the existence check so a new record can be created when it’s missing.
-
#valid? ⇒ Boolean
only run validations if a model has been provided.
Methods inherited from UpdateUpsert
Methods inherited from Action
#add, #add_timestamps, #changes_applied, #delete, #find_from_attributes, #hash_key, #model_class, #raise_validation_error?, #range_key, #run_callbacks, #sanitize_item, #set, #skip_callbacks?, #skip_validation?, #to_h, #touch_model_timestamps, #write_attributes_to_model
Constructor Details
#initialize(model_or_model_class, attributes, options = {}) ⇒ Upsert
Upsert is just like Update buts skips the existence check so a new record can be created when it’s missing. No callbacks.
10 11 12 13 14 15 |
# File 'lib/dynamoid/transaction_write/upsert.rb', line 10 def initialize(model_or_model_class, attributes, = {}) = .reverse_merge(skip_existence_check: true) super(model_or_model_class, attributes, ) raise Dynamoid::Errors::MissingHashKey unless hash_key.present? raise Dynamoid::Errors::MissingRangeKey unless !model_class.range_key? || range_key.present? end |
Instance Method Details
#valid? ⇒ Boolean
only run validations if a model has been provided
20 21 22 |
# File 'lib/dynamoid/transaction_write/upsert.rb', line 20 def valid? model ? model.valid? : true end |