abstract class Avram::SaveOperation(T)
- Avram::SaveOperation(T)
- Reference
- Object
Included Modules
- Avram::AddColumnAttributes
- 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 : String
-
.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.
Macro Summary
- add_cast_value_methods(columns)
- param_key(key)
- permit_columns(*attribute_names)
-
skip_default_validations
This allows you to skip the default validations which may be used as an escape hatch when you want to allow storing an empty string value.
Instance Method Summary
- #after_commit(_record : T)
- #after_save(_record : T)
- #attributes
- #before_save
- #changes : Hash(Symbol, String | Nil)
- #created? : Bool
- #custom_errors : Hash(Symbol, Array(String))
- #database(*args, **options)
- #database(*args, **options, &)
- #generic_attributes : Array(Avram::GenericAttribute)
-
#new_record? : Bool
#persisted?
always returnstrue
inafter_*
hooks, whether a new record was created, or an existing one was updated. - #params : Avram::Paramable
- #persisted? : Bool
- #primary_key_name(*args, **options)
- #primary_key_name(*args, **options, &)
-
#run_default_validations : Nil
Runs all required validations for required types as well as any additional valitaions the type needs to run e.g.
- #save : Bool
- #save! : T
-
#save_failed? : Bool
Return true if the operation has run and the record failed to save
- #save_status : OperationStatus
- #save_status=(save_status : OperationStatus)
-
#saved? : Bool
Returns true if the operation has run and saved the record successfully
- #table_name(*args, **options)
- #table_name(*args, **options, &)
- #update! : T
- #updated? : Bool
-
#valid? : Bool
Runs required validation, then returns
true
if all attributes are valid, and there's no custom errors
Macros inherited from module Avram::Upsert
upsert_lookup_columns(*attribute_names)
upsert_lookup_columns
Macros inherited from module Avram::InheritColumnAttributes
inherit_column_attributes
inherit_column_attributes
Instance methods inherited from module Avram::MarkAsFailed
mark_as_failed : Nil
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
Macros inherited from module Avram::NestedSaveOperation
has_one(type_declaration)
has_one
Macros inherited from module Avram::Callbacks
after_commit(method_name, if _if = nil, unless _unless = nil)after_commit(if _if = nil, unless _unless = nil, &block) after_commit, after_delete(method_name, if _if = nil, unless _unless = nil)
after_delete(if _if = nil, unless _unless = nil, &block) after_delete, after_run(method_name)
after_run(&block) after_run, after_save(method_name, if _if = nil, unless _unless = nil)
after_save(if _if = nil, unless _unless = nil, &block) after_save, before_delete(method_name, if _if = nil, unless _unless = nil)
before_delete(if _if = nil, unless _unless = nil) before_delete, before_run(method_name)
before_run before_run, before_save(method_name, if _if = nil, unless _unless = nil)
before_save(if _if = nil, unless _unless = nil) before_save, conditional_error_for_block_callbacks(callback, condition) conditional_error_for_block_callbacks
Macros inherited from module Avram::NeedyInitializerAndSaveMethods
generate_create(attribute_method_args, attribute_params, with_params, with_bang)
generate_create,
generate_initializer(attribute_method_args, attribute_params)
generate_initializer,
generate_initializer_and_save_methods
generate_initializer_and_save_methods,
generate_save_methods(attribute_method_args, attribute_params)
generate_save_methods,
generate_update(attribute_method_args, attribute_params, with_params, with_bang)
generate_update,
hash_is_not_allowed_helpful_error(method, additional_args = nil)
hash_is_not_allowed_helpful_error,
inherit_needs
inherit_needs,
needs(type_declaration)
needs
Macros inherited from module Avram::ParamKeyOverride
define_param_key_override
define_param_key_override
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 = Avram.settings.i18n_backend.get(:validate_acceptance_of)) : Bool
validate_acceptance_of,
validate_at_most_one_filled(*attributes, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_at_most_one_filled)) : Bool
validate_at_most_one_filled,
validate_confirmation_of(attribute : Avram::Attribute(T), with confirmation_attribute : Avram::Attribute(T), message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_confirmation_of)) : Bool forall T
validate_confirmation_of,
validate_exactly_one_filled(*attributes, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_exactly_one_filled)) : Bool
validate_exactly_one_filled,
validate_format_of(attribute : Avram::Attribute(String), with regex : Regex, match : Bool = true, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_format_of), allow_nil : Bool = false) : Bool
validate_format_of,
validate_inclusion_of(attribute : Avram::Attribute(T), in allowed_values : Enumerable(T), message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_inclusion_of), allow_nil : Bool = false) : Bool forall T
validate_inclusion_of,
validate_numeric(attribute : Avram::Attribute(Number), greater_than = nil, less_than = nil, message = nil, allow_nil : Bool = false) : Boolvalidate_numeric(attribute : Avram::Attribute(Number), *, at_least = nil, no_more_than = nil, message = nil, allow_nil : Bool = false) : Bool validate_numeric, validate_required(*attributes, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_required)) : Bool validate_required, validate_size_of(attribute : Avram::Attribute(String) | Avram::Attribute(Array(T)), min : Number | Nil = nil, max : Number | Nil = nil, message : Avram::Attribute::ErrorMessage | Nil = nil, allow_nil : Bool = false) : Bool forall T
validate_size_of(attribute : Avram::Attribute(String) | Avram::Attribute(Array(T)), *, is exact_size : Number, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_exact_size_of), allow_nil : Bool = false) : Bool forall T validate_size_of, validate_url_format(attribute : Avram::Attribute(String), scheme : String = "https", message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_url_format)) : Bool validate_url_format
Macros inherited from module Avram::Validations
default_validations
default_validations
Instance methods inherited from module Avram::DefineAttribute
attributes
attributes
Macros inherited from module Avram::DefineAttribute
attribute(type_declaration)
attribute,
ensure_base_attributes_method_is_present
ensure_base_attributes_method_is_present,
file_attribute(key)
file_attribute,
inherit_attributes
inherit_attributes
Instance methods inherited from class Object
blank_for_validates_required? : Bool
blank_for_validates_required?
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.
Macro Detail
This allows you to skip the default validations which may be used as an escape hatch when you want to allow storing an empty string value.
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 all required validations for required types as well as any additional valitaions the type needs to run e.g. polymorphic validations
Return true if the operation has run and the record failed to save
Returns true if the operation has run and saved the record successfully
Runs required validation,
then returns true
if all attributes are valid,
and there's no custom errors