abstract struct DynFork::Extra
- DynFork::Extra
- Struct
- Value
- Object
Overview
Methods of additional abstraction.
Additional validation - It is supposed to be use to additional validation of fields.
Indexing - For set up and start indexing.
Hooks - Methods that are called at different stages when accessing the database.
Direct Known Subclasses
Defined in:
dynfork/extra.crConstructors
Class Method Summary
-
.indexing : Nil
For set up and start indexing.
Instance Method Summary
-
#add_validation : Hash(String, String)
It is supposed to be use to additional validation of fields.
- #initialize
-
#post_create : Nil
Called after a new document has been created in the database.
-
#post_delete : Nil
Called after an existing document in the database has been deleted.
-
#post_update : Nil
Called after an existing document in the database is updated.
-
#pre_create : Nil
Called before a new document is created in the database.
-
#pre_delete : Nil
Called before deleting an existing document in the database.
-
#pre_update : Nil
Called before updating an existing document in the database.
Constructor Detail
Class Method Detail
For set up and start indexing.
NOTE How to use, see example.
NOTE For more details, please check the official documentation.
WARNING Runs automatically during Model migration.
Example:
@[DynFork::Meta(service_name: "Accounts")]
struct User < DynFork::Model
getter username = DynFork::Fields::TextField.new(unique: true)
getter email = DynFork::Fields::EmailField.new(unique: true)
def self.indexing
self.create_index(
keys: {
"username": 1,
},
options: {
unique: true,
name: "usernameIdx",
}
)
end
end
Instance Method Detail
It is supposed to be use to additional validation of fields.
NOTE How to use, see example.
WARNING The method is called automatically when checking or saving the Model.
Example:
@[DynFork::Meta(service_name: "Accounts")]
struct User < DynFork::Model
getter username = DynFork::Fields::TextField.new
getter password = DynFork::Fields::PasswordField.new
getter confirm_password = DynFork::Fields::PasswordField.new(
"ignored": true
)
private def add_validation : Hash(String, String)
error_map = Hash(String, String).new
# Get clean data.
password : String? = @password.value?
confirm_password : String? = @confirm_password.value?
# Fields validation.
if password != confirm_password
error_map["confirm_password"] = "Password confirmation does not match."
end
error_map
end
end
Called after a new document has been created in the database.
NOTE How to use, see example.
WARNING The method is called automatically.
Called after an existing document in the database has been deleted.
NOTE How to use, see example.
WARNING The method is called automatically.
Called after an existing document in the database is updated.
NOTE How to use, see example.
WARNING The method is called automatically.
Called before a new document is created in the database.
NOTE How to use, see example.
WARNING The method is called automatically.
Called before deleting an existing document in the database.
NOTE How to use, see example.
WARNING The method is called automatically.