24

Oct 2019

Module CRUD - Model Validation

Model Validation

AURORA model validation is one of the features that is used for conducting or checking tables and fields with the rules that have been provided. Modeling can be made through the generator model

aurora model:create  -t 

for creating model without target table:

aurora model:create 

Model validation can also be made manually without using generate by making a model file on the model folder with javascript format

The content of the aurora validation model file:

module.exports.table_name = " ";

module.exports.rulesOnCreate = {

};

module.exports.rulesOnUpdate = {

};

table_name can be filled in which table will be installed aurora model validation,

Example:

module.exports.table_name = "membersTable";

In the rulesOnCreate and rulesOnUpdate sections, they can be filled in with the appropriate fields in the intended table and what validation they want to install.


Rules For Validating

Rules for validating aurora that can be used:

Rules

Example

required

{
UID : ”required”
}

 

string

{
name:”string”
}

 

number

{
UID:”required,number”
}

 

boolean


-

array

{
Name:”array”
}

 

email

{
Email:”email”
}

 

password_confirmation

{
password : “password_confirmation”
}

 

min

{
Name: “min=> 5”
}

 

max

{
Name:”max=>5”
}

 

 

Example the using of the rules:

module.exports.table_name = "table_name";
module.exports.rulesOnCreate = {
'field_name' : "array, required, max => 2, min => 5, email, password_confirmation, 
message_required => error required, message_min => error min"
}

module.exports.rulesOnUpdate = {
'field_name' : "array, required, max => 2, min => 5, email, password_confirmation, 
message_required => error required, message_min => error min"
}