Skip to content

Commit

Permalink
[skip ci][doc] start new model command
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Dec 3, 2021
1 parent bed4866 commit 2678671
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 2 deletions.
Binary file added docs/_static/images/model/scratch/add-fields.png
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.
Binary file added docs/_static/images/model/scratch/field-types.png
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.
Binary file added docs/_static/images/model/scratch/user-model.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions docs/model/generation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Models generation
From existing database
----------------------

- :doc:`with console </model/generation/db-console>`
- :doc:`with web-tools </model/generation/db-html>`
- :doc:`with devtools </model/generation/db-console>`
- :doc:`with webtools </model/generation/db-html>`

From scratch
------------

- :doc:`with devtools </model/generation/scratch>`



143 changes: 143 additions & 0 deletions docs/model/generation/scratch.rst
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 />

0 comments on commit 2678671

Please sign in to comment.