Skip to content

Commit 08001c7

Browse files
committed
minor #8119 Stop recommending the use of "doctrine:generate:entities" (javiereguiluz)
This PR was squashed before being merged into the 2.7 branch (closes #8119). Discussion ---------- Stop recommending the use of "doctrine:generate:entities" This fixes #5070. Commits ------- ad491a0 Stop recommending the use of "doctrine:generate:entities"
2 parents da6afe8 + ad491a0 commit 08001c7

File tree

5 files changed

+13
-83
lines changed

5 files changed

+13
-83
lines changed

doctrine.rst

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -400,56 +400,8 @@ Even though Doctrine now knows how to persist a ``Product`` object to the
400400
database, the class itself isn't really useful yet. Since ``Product`` is just
401401
a regular PHP class with ``private`` properties, you need to create ``public``
402402
getter and setter methods (e.g. ``getName()``, ``setName($name)``) in order
403-
to access its properties in the rest of your application's code. Fortunately,
404-
the following command can generate these boilerplate methods automatically:
405-
406-
.. code-block:: terminal
407-
408-
$ php app/console doctrine:generate:entities AppBundle/Entity/Product
409-
410-
This command makes sure that all the getters and setters are generated
411-
for the ``Product`` class. This is a safe command - you can run it over and
412-
over again: it only generates getters and setters that don't exist (i.e. it
413-
doesn't replace your existing methods).
414-
415-
.. caution::
416-
417-
Keep in mind that Doctrine's entity generator produces simple getters/setters.
418-
You should review the generated methods and add any logic, if necessary,
419-
to suit the needs of your application.
420-
421-
.. sidebar:: More about ``doctrine:generate:entities``
422-
423-
With the ``doctrine:generate:entities`` command you can:
424-
425-
* generate getter and setter methods in entity classes;
426-
427-
* generate repository classes on behalf of entities configured with the
428-
``@ORM\Entity(repositoryClass="...")`` annotation;
429-
430-
* generate the appropriate constructor for 1:n and n:m relations.
431-
432-
The ``doctrine:generate:entities`` command saves a backup of the original
433-
``Product.php`` named ``Product.php~``. In some cases, the presence of
434-
this file can cause a "Cannot redeclare class" error. It can be safely
435-
removed. You can also use the ``--no-backup`` option to prevent generating
436-
these backup files.
437-
438-
Note that you don't *need* to use this command. You could also write the
439-
necessary getters and setters by hand. This option simply exists to save
440-
you time, since creating these methods is often a common task during
441-
development.
442-
443-
You can also generate all known entities (i.e. any PHP class with Doctrine
444-
mapping information) of a bundle or an entire namespace:
445-
446-
.. code-block:: terminal
447-
448-
# generates all entities in the AppBundle
449-
$ php app/console doctrine:generate:entities AppBundle
450-
451-
# generates all entities of bundles in the Acme namespace
452-
$ php app/console doctrine:generate:entities Acme
403+
to access its properties in the rest of your application's code. Add these
404+
methods manually or with your own IDE.
453405

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

doctrine/associations.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,8 @@ own a collection of its related ``Product`` objects.
189189
namespace as the targetEntity.
190190

191191
Now that you've added new properties to both the ``Product`` and ``Category``
192-
classes, tell Doctrine to generate the missing getter and setter methods for you:
193-
194-
.. code-block:: terminal
195-
196-
$ php app/console doctrine:generate:entities AppBundle
192+
classes, you must generate the missing getter and setter methods manually or
193+
using your own IDE.
197194

198195
Ignore the Doctrine metadata for a moment. You now have two classes - ``Product``
199196
and ``Category``, with a natural many-to-one relationship. The ``Product``

doctrine/repository.rst

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,8 @@ To do this, add the repository class name to your entity's mapping definition:
5353
</entity>
5454
</doctrine-mapping>
5555
56-
Doctrine can generate empty repository classes for all the entities in your
57-
application via the same command used earlier to generate the missing getter
58-
and setter methods:
59-
60-
.. code-block:: terminal
61-
62-
$ php app/console doctrine:generate:entities AppBundle
63-
64-
.. tip::
65-
66-
If you opt to create the repository classes yourself, they must extend
67-
``Doctrine\ORM\EntityRepository``.
56+
Then, create an empty ``AppBundle\Repository\ProductRepository`` class extending
57+
from ``Doctrine\ORM\EntityRepository``.
6858

6959
Next, add a new method - ``findAllOrderedByName()`` - to the newly-generated
7060
``ProductRepository`` class. This method will query for all the ``Product``

doctrine/reverse_engineering.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,17 @@ The generated ``BlogPost.orm.xml`` metadata file looks as follows:
8888
</doctrine-mapping>
8989
9090
Once the metadata files are generated, you can ask Doctrine to build related
91-
entity classes by executing the following two commands.
91+
entity classes by executing the following command.
9292

9393
.. code-block:: terminal
9494
95+
// generates entity classes with annotation mappings
9596
$ php app/console doctrine:mapping:convert annotation ./src
96-
$ php app/console doctrine:generate:entities AcmeBlogBundle
97-
98-
The first command generates entity classes with annotation mappings. But
99-
if you want to use YAML or XML mapping instead of annotations, you should
100-
execute the second command only.
10197
10298
.. caution::
10399

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

108104
For example, the newly created ``BlogComment`` entity class looks as follow::

security/entity_provider.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,7 @@ For this entry, suppose that you already have a ``User`` entity inside an
140140
}
141141
142142
To make things shorter, some of the getter and setter methods aren't shown.
143-
But you can :ref:`generate <doctrine-generating-getters-and-setters>` these
144-
by running:
145-
146-
.. code-block:: terminal
147-
148-
$ php app/console doctrine:generate:entities AppBundle/Entity/User
143+
But you can generate these manually or with your own IDE.
149144

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

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

172167
.. caution::
173168

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

179174
What do the serialize and unserialize Methods do?

0 commit comments

Comments
 (0)