Generate models from Database with devtools¶
In this part, your project is already created.
If you do not have a mysql database on hand, you can download this one:
Check the database configuration with devtools console program:
Ubiquity config database
The configuration file is located in app/config/config.php
Change the configuration of the database to use the messagerie database:
Ubiquity config:set --database.dbName=messagerie
To generate all models, use the all-models command:
The models are generated and operational.
It is possible to generate models automatically when creating a project with the
-m option for models and
-b to specify the database:
Ubiquity new quick-start -a -m -b=messagerie
To obtain the metadatas of all created models:
For a precise model:
Ubiquity info:models -m=Groupe
Models validation info¶
To obtain the validation rules for the model User:
Ubiquity info:validation -m=User
On a particular member (email):
Ubiquity info:validation -m=User -f=email
Generated classes are located in app/models folder, if the configuration of mvcNS.models has not been changed.
If you want to know more about:
The User class:
Any modification on the classes (code or annotations) requires the reset of the cache to be taken into account.
Ubiquity init-cache -t=models
Classes are generated, and models cache also.
At this point, we can already query the database in console mode, to give an idea of the possibilities of the DAO part:
Getting all the groups:
Ubiquity dao getAll -r=Groupe
With there organization:
Ubiquity dao getAll -r=Groupe -i=organization
A more complete query:
Search for groups with the word “list” in their email, displaying the name, email and organization of each group:
Ubiquity dao getAll -r=Groupe -c="email like '%liste%'" -f=email,name,organization -i=organization
Getting one User by id:
Ubiquity dao getOne -r=User -c="id=4"
UQueries are special in that they allow to set criteria on the values of the members of the associated objects:
Search for groups with a user named Shermans
Ubiquity dao uGetAll -r=Groupe -c="users.lastname='Shermans'" -i=users
We can verify that Shermans belongs to the group Auditeurs
Ubiquity dao uGetAll -r=User -c="groupes.name='Auditeurs' and lastname='Shermans'" -i=groupes
The same with a parameterized query:
Ubiquity dao uGetAll -r=User -c="groupes.name= ? and lastname= ?" -i=groupes -p=Auditeurs,Shermans