DynFork::Extra
Methods of additional abstraction.
NOTE: Additional validation - It is supposed to be use to additional validation of fields.
NOTE: Indexing - For set up and start indexing.
NOTE: Hooks - Methods that are called at different stages when accessing the database.
Constructors
Class methods
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 methods
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.