-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci][doc] start new model command
- Loading branch information
Showing
15 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
Models creation from scratch | ||
============================ | ||
.. note:: | ||
It is often preferable to design a database conceptually and then generate the models from the existing database. |br| | ||
The creation of models from scratch is only suitable for simple cases, and does not allow to skip a conceptualization phase. | ||
|
||
Creating a model | ||
---------------- | ||
Consider the following model representing a user: | ||
|
||
.. image:: /_static/images/model/scratch/user-model.png | ||
:class: bordered | ||
|
||
We will create it with devtools, in command prompt: | ||
|
||
.. code-block:: bash | ||
Ubiquity model user | ||
.. image:: /_static/images/model/scratch/create-model.png | ||
:class: bordered | ||
|
||
.. note:: | ||
A primary key is automatically added at creation as an auto-increment. |br| | ||
It is possible to change the default name of the primary key when launching the command : | ||
.. code-block:: bash | ||
Ubiquity model user -k=uid | ||
Adding fields | ||
^^^^^^^^^^^^^ | ||
Select the `Add fields` menu item: | ||
|
||
- Enter the field names separated by a comma: | ||
|
||
.. image:: /_static/images/model/scratch/add-fields.png | ||
:class: bordered | ||
|
||
- Enter the field types (db types) in the same way. | ||
- Provide the list of nullable fields. | ||
|
||
.. image:: /_static/images/model/scratch/field-types.png | ||
:class: bordered | ||
|
||
The added fields: | ||
|
||
.. image:: /_static/images/model/scratch/fields-added.png | ||
:class: bordered | ||
|
||
Generating the class | ||
^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. image:: /_static/images/model/scratch/generated-class.png | ||
:class: bordered | ||
|
||
Below is the created model, without the accessors: | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Attributes | ||
|
||
.. code-block:: php | ||
:linenos: | ||
:caption: app/models/User.php | ||
namespace models; | ||
use Ubiquity\attributes\items\Table; | ||
use Ubiquity\attributes\items\Id; | ||
#[Table('user')] | ||
class User{ | ||
#[Id] | ||
#[Column(name: "id",dbType: "int(11)")] | ||
#[Validator(type: "id",constraints: ["autoinc"=>true])] | ||
private $id; | ||
#[Column(name: "firstname",dbType: "varchar(30)")] | ||
#[Validator(type: "length",constraints: ["max"=>30,"notNull"=>false])] | ||
private $firstname; | ||
#[Column(name: "lastname",dbType: "varchar(45)")] | ||
#[Validator(type: "length",constraints: ["max"=>45,"notNull"=>false])] | ||
private $lastname; | ||
#[Column(name: "email",dbType: "varchar(150)")] | ||
#[Validator(type: "email",constraints: ["notNull"=>true])] | ||
#[Validator(type: "length",constraints: ["max"=>150])] | ||
private $email; | ||
} | ||
.. tab:: Annotations | ||
|
||
.. code-block:: php | ||
:linenos: | ||
:caption: app/models/User.php | ||
namespace models; | ||
/** | ||
* @table("name"=>"user") | ||
*/ | ||
class User{ | ||
/** | ||
* @id | ||
* @column("id","int(11)") | ||
* @validator("id",["autoinc"=>true]) | ||
*/ | ||
private $id; | ||
/** | ||
* @column("firstname","varchar(30)") | ||
* @validator("length",["max"=>30,"notNull"=>false]) | ||
*/ | ||
private $firstname; | ||
/** | ||
* @column("lastname","varchar(45)") | ||
* @validator("length",["max"=>45,"notNull"=>false]) | ||
*/ | ||
private $lastname; | ||
/** | ||
* @column("firstname","varchar(150)") | ||
* @validator("email",["notNull"=>false]) | ||
* @validator("length",["max"=>150]) | ||
*/ | ||
private $email; | ||
} | ||
Modifying existing models | ||
------------------------- | ||
.. code-block:: bash | ||
Ubiquity model | ||
.. |br| raw:: html | ||
|
||
<br /> |