Skip to content

Commit

Permalink
minor symfony#8119 Stop recommending the use of "doctrine:generate:en…
Browse files Browse the repository at this point in the history
…tities" (javiereguiluz)

This PR was squashed before being merged into the 2.7 branch (closes symfony#8119).

Discussion
----------

Stop recommending the use of "doctrine:generate:entities"

This fixes symfony#5070.

Commits
-------

ad491a0 Stop recommending the use of "doctrine:generate:entities"
  • Loading branch information
xabbuh committed Jul 7, 2017
2 parents da6afe8 + ad491a0 commit 08001c7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 83 deletions.
52 changes: 2 additions & 50 deletions doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -400,56 +400,8 @@ Even though Doctrine now knows how to persist a ``Product`` object to the
database, the class itself isn't really useful yet. Since ``Product`` is just
a regular PHP class with ``private`` properties, you need to create ``public``
getter and setter methods (e.g. ``getName()``, ``setName($name)``) in order
to access its properties in the rest of your application's code. Fortunately,
the following command can generate these boilerplate methods automatically:

.. code-block:: terminal
$ php app/console doctrine:generate:entities AppBundle/Entity/Product
This command makes sure that all the getters and setters are generated
for the ``Product`` class. This is a safe command - you can run it over and
over again: it only generates getters and setters that don't exist (i.e. it
doesn't replace your existing methods).

.. caution::

Keep in mind that Doctrine's entity generator produces simple getters/setters.
You should review the generated methods and add any logic, if necessary,
to suit the needs of your application.

.. sidebar:: More about ``doctrine:generate:entities``

With the ``doctrine:generate:entities`` command you can:

* generate getter and setter methods in entity classes;

* generate repository classes on behalf of entities configured with the
``@ORM\Entity(repositoryClass="...")`` annotation;

* generate the appropriate constructor for 1:n and n:m relations.

The ``doctrine:generate:entities`` command saves a backup of the original
``Product.php`` named ``Product.php~``. In some cases, the presence of
this file can cause a "Cannot redeclare class" error. It can be safely
removed. You can also use the ``--no-backup`` option to prevent generating
these backup files.

Note that you don't *need* to use this command. You could also write the
necessary getters and setters by hand. This option simply exists to save
you time, since creating these methods is often a common task during
development.

You can also generate all known entities (i.e. any PHP class with Doctrine
mapping information) of a bundle or an entire namespace:

.. code-block:: terminal
# generates all entities in the AppBundle
$ php app/console doctrine:generate:entities AppBundle
# generates all entities of bundles in the Acme namespace
$ php app/console doctrine:generate:entities Acme
to access its properties in the rest of your application's code. Add these
methods manually or with your own IDE.

.. _doctrine-creating-the-database-tables-schema:

Expand Down
7 changes: 2 additions & 5 deletions doctrine/associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,8 @@ own a collection of its related ``Product`` objects.
namespace as the targetEntity.

Now that you've added new properties to both the ``Product`` and ``Category``
classes, tell Doctrine to generate the missing getter and setter methods for you:

.. code-block:: terminal
$ php app/console doctrine:generate:entities AppBundle
classes, you must generate the missing getter and setter methods manually or
using your own IDE.

Ignore the Doctrine metadata for a moment. You now have two classes - ``Product``
and ``Category``, with a natural many-to-one relationship. The ``Product``
Expand Down
14 changes: 2 additions & 12 deletions doctrine/repository.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,8 @@ To do this, add the repository class name to your entity's mapping definition:
</entity>
</doctrine-mapping>
Doctrine can generate empty repository classes for all the entities in your
application via the same command used earlier to generate the missing getter
and setter methods:

.. code-block:: terminal
$ php app/console doctrine:generate:entities AppBundle
.. tip::

If you opt to create the repository classes yourself, they must extend
``Doctrine\ORM\EntityRepository``.
Then, create an empty ``AppBundle\Repository\ProductRepository`` class extending
from ``Doctrine\ORM\EntityRepository``.

Next, add a new method - ``findAllOrderedByName()`` - to the newly-generated
``ProductRepository`` class. This method will query for all the ``Product``
Expand Down
10 changes: 3 additions & 7 deletions doctrine/reverse_engineering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,17 @@ The generated ``BlogPost.orm.xml`` metadata file looks as follows:
</doctrine-mapping>
Once the metadata files are generated, you can ask Doctrine to build related
entity classes by executing the following two commands.
entity classes by executing the following command.

.. code-block:: terminal
// generates entity classes with annotation mappings
$ php app/console doctrine:mapping:convert annotation ./src
$ php app/console doctrine:generate:entities AcmeBlogBundle
The first command generates entity classes with annotation mappings. But
if you want to use YAML or XML mapping instead of annotations, you should
execute the second command only.
.. caution::

If you want to use annotations, you must remove the XML (or YAML) files
after running these two commands. This is necessary as
after running this command. This is necessary as
:ref:`it is not possible to mix mapping configuration formats <doctrine-adding-mapping>`

For example, the newly created ``BlogComment`` entity class looks as follow::
Expand Down
13 changes: 4 additions & 9 deletions security/entity_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ For this entry, suppose that you already have a ``User`` entity inside an
}
To make things shorter, some of the getter and setter methods aren't shown.
But you can :ref:`generate <doctrine-generating-getters-and-setters>` these
by running:

.. code-block:: terminal
$ php app/console doctrine:generate:entities AppBundle/Entity/User
But you can generate these manually or with your own IDE.

Next, make sure to :ref:`create the database table <doctrine-creating-the-database-tables-schema>`:

Expand All @@ -171,9 +166,9 @@ To learn more about each of these, see :class:`Symfony\\Component\\Security\\Cor

.. caution::

The ``eraseCredentials()`` method is only meant to clean up possibly stored
plain text passwords (or similar credentials). Be careful what to erase
if your user class is also mapped to a database as the modified object
The ``eraseCredentials()`` method is only meant to clean up possibly stored
plain text passwords (or similar credentials). Be careful what to erase
if your user class is also mapped to a database as the modified object
will likely be persisted during the request.

What do the serialize and unserialize Methods do?
Expand Down

0 comments on commit 08001c7

Please sign in to comment.