abstract class Avram::SaveOperation(T)
- Avram::SaveOperation(T)
- Reference
- Object
Included Modules
- Avram::Callbacks
- Avram::DatabaseValidations(T)
- Avram::DefineAttribute
- Avram::InheritColumnAttributes
- Avram::MarkAsFailed
- Avram::NeedyInitializerAndSaveMethods
- Avram::NestedSaveOperation
- Avram::OperationErrors
- Avram::ParamKeyOverride
- Avram::Upsert
- Avram::Validations
Defined in:
avram/save_operation.crConstant Summary
-
ATTRIBUTES =
[] of Nil
-
OPERATION_NEEDS =
[] of Nil
Constructors
Class Method Summary
- .param_key
-
.upsert(*args, **named_args)
Performs a create or update depending on if there is a conflicting row in the database.
-
.upsert!(*args, **named_args)
Performs a create or update depending on if there is a conflicting row in the database.
Instance Method Summary
- #after_commit(_record : T)
- #after_save(_record : T)
- #attributes
- #before_save
- #changes : Hash(Symbol, String | Nil)
- #custom_errors
- #database(*args, **options)
- #database(*args, **options, &)
- #generic_attributes
-
#new_record? : Bool
#persisted?
always returnstrue
inafter_*
hooks, whether a new record was created, or an existing one was updated. - #params
- #persisted? : Bool
- #primary_key_name(*args, **options)
- #primary_key_name(*args, **options, &)
- #record
- #save : Bool
- #save! : T
-
#save_failed?
Return true if the operation has run and the record failed to save
- #save_status : SaveStatus
- #save_status=(save_status : SaveStatus)
-
#saved?
Returns true if the operation has run and saved the record successfully
- #table_name(*args, **options)
- #table_name(*args, **options, &)
- #update! : T
-
#valid? : Bool
Runs required validation, then returns
true
if all attributes are valid, and there's no custom errors
Macro Summary
Instance methods inherited from module Avram::MarkAsFailed
mark_as_failed
mark_as_failed
Instance methods inherited from module Avram::NestedSaveOperation
mark_nested_save_operations_as_failed
mark_nested_save_operations_as_failed,
nested_save_operations
nested_save_operations
Instance methods inherited from module Avram::OperationErrors
add_error(key : Symbol, message : String) : Nil
add_error,
errors : Hash(Symbol, Array(String))
errors
Instance methods inherited from module Avram::Validations
validate_acceptance_of(attribute : Avram::Attribute(Bool), message : Avram::Attribute::ErrorMessage = "must be accepted")
validate_acceptance_of,
validate_at_most_one_filled(*attributes, message : Avram::Attribute::ErrorMessage = "must be blank")
validate_at_most_one_filled,
validate_confirmation_of(attribute : Avram::Attribute(T), with confirmation_attribute : Avram::Attribute(T), message : Avram::Attribute::ErrorMessage = "must match") forall T
validate_confirmation_of,
validate_exactly_one_filled(*attributes, message : Avram::Attribute::ErrorMessage = "at least one must be filled")
validate_exactly_one_filled,
validate_inclusion_of(attribute : Avram::Attribute(T), in allowed_values : Enumerable(T), message : Avram::Attribute::ErrorMessage = "is invalid", allow_nil : Bool = false) forall T
validate_inclusion_of,
validate_numeric(attribute : Avram::Attribute(Number), greater_than = nil, less_than = nil, message = nil, allow_nil : Bool = false)
validate_numeric,
validate_required(*attributes, message : Avram::Attribute::ErrorMessage = "is required")
validate_required,
validate_size_of(attribute : Avram::Attribute(String), min = nil, max = nil, message = nil, allow_nil : Bool = false)validate_size_of(attribute : Avram::Attribute(String), *, is exact_size, message : Avram::Attribute::ErrorMessage = "is invalid", allow_nil : Bool = false) validate_size_of
Instance methods inherited from module Avram::DefineAttribute
attributes
attributes
Instance methods inherited from class Object
blank?
blank?,
blank_for_validates_required? : Bool
blank_for_validates_required?,
present?
present?
Constructor Detail
Class Method Detail
Performs a create or update depending on if there is a conflicting row in the database.
See Avram::Upsert.upsert_lookup_columns
for full documentation and examples.
Performs a create or update depending on if there is a conflicting row in the database.
See Avram::Upsert.upsert_lookup_columns
for full documentation and examples.
Instance Method Detail
#persisted?
always returns true
in after_*
hooks, whether
a new record was created, or an existing one was updated.
This method should always return true
for a create or false
for an update, independent of the stage we are at in the operation.
Runs required validation,
then returns true
if all attributes are valid,
and there's no custom errors