Skip to content

Commit a40e44c

Browse files
committed
[symfony#2578] More tweaks to reverse engineering after running through the chapter myself
1 parent 02c73c2 commit a40e44c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

cookbook/doctrine/reverse_engineering.rst

+30-30
Original file line numberDiff line numberDiff line change
@@ -64,60 +64,55 @@ tables fields.
6464
6565
This command line tool asks Doctrine to introspect the database and generate
6666
the XML metadata files under the ``src/Acme/BlogBundle/Resources/config/doctrine``
67-
folder of your bundle.
67+
folder of your bundle. This generates two files: ``BlogPost.orm.xml`` and
68+
``BlogComment.orm.xml``.
6869

6970
.. tip::
7071

7172
It's also possible to generate metadata class in YAML format by changing the
72-
first argument to `yml`.
73+
first argument to ``yml``.
7374

7475
The generated ``BlogPost.orm.xml`` metadata file looks as follows:
7576

7677
.. code-block:: xml
7778
7879
<?xml version="1.0" encoding="utf-8"?>
79-
<doctrine-mapping>
80+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
8081
<entity name="BlogPost" table="blog_post">
81-
<change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy>
8282
<id name="id" type="bigint" column="id">
8383
<generator strategy="IDENTITY"/>
8484
</id>
85-
<field name="title" type="string" column="title" length="100"/>
86-
<field name="content" type="text" column="content"/>
87-
<field name="isPublished" type="boolean" column="is_published"/>
88-
<field name="createdAt" type="datetime" column="created_at"/>
89-
<field name="updatedAt" type="datetime" column="updated_at"/>
90-
<field name="slug" type="string" column="slug" length="255"/>
91-
<lifecycle-callbacks/>
85+
<field name="title" type="string" column="title" length="100" nullable="false"/>
86+
<field name="content" type="text" column="content" nullable="false"/>
87+
<field name="createdAt" type="datetime" column="created_at" nullable="false"/>
9288
</entity>
9389
</doctrine-mapping>
9490
95-
Then you should insert proper namespace in ``name`` attribute of ``entity`` element like this:
91+
Update the namespace in the ``name`` attribute of the ``entity`` element like
92+
this:
9693

9794
.. code-block:: xml
9895
99-
<entity name="Acme\BlogBundle\BlogPost" table="blog_post">
96+
<entity name="Acme\BlogBundle\Entity\BlogPost" table="blog_post">
10097
101-
.. note::
102-
103-
If you have ``oneToMany`` relationships between your entities,
104-
you will need to edit the generated ``xml`` or ``yml`` files to add
105-
a section on the specific entities for ``oneToMany`` defining the
106-
``inversedBy`` and the ``mappedBy`` pieces.
107-
108-
Once the metadata files are generated, you can ask Doctrine to build related entity classes by executing the following two commands.
98+
Once the metadata files are generated, you can ask Doctrine to build related
99+
entity classes by executing the following two commands.
109100

110101
.. code-block:: bash
111102
112103
$ php app/console doctrine:mapping:convert annotation ./src
113104
$ php app/console doctrine:generate:entities AcmeBlogBundle
114105
115-
The first command generates entity classes with an annotations mapping. But if you want to use yml or xml mapping instead of annotations, you should execute the second command only.
116-
The newly created ``BlogComment`` entity class looks as follow:
106+
The first command generates entity classes with an annotations mapping. But
107+
if you want to use yml or xml mapping instead of annotations, you should
108+
execute the second command only.
109+
110+
.. tip::
117111

118-
.. code-block:: php
112+
If you want to use annotations, you can safely delete the XML files after
113+
running these two commands.
119114

120-
<?php
115+
For example, the newly created ``BlogComment`` entity class looks as follow::
121116

122117
// src/Acme/BlogBundle/Entity/BlogComment.php
123118
namespace Acme\BlogBundle\Entity;
@@ -133,9 +128,9 @@ The newly created ``BlogComment`` entity class looks as follow:
133128
class BlogComment
134129
{
135130
/**
136-
* @var bigint $id
131+
* @var integer $id
137132
*
138-
* @ORM\Column(name="id", type="bigint", nullable=false)
133+
* @ORM\Column(name="id", type="bigint")
139134
* @ORM\Id
140135
* @ORM\GeneratedValue(strategy="IDENTITY")
141136
*/
@@ -177,8 +172,13 @@ relationship with the ``BlogPost`` entity class based on the foreign key constra
177172
Consequently, you can find a private ``$post`` property mapped with a ``BlogPost``
178173
entity in the ``BlogComment`` entity class.
179174

180-
The last command generated all getters and setters for your two ``BlogPost`` and
181-
``BlogComment`` entity class properties. The generated entities are now ready to be
182-
used. Have fun!
175+
.. note::
176+
177+
If you want to have a ``oneToMany`` relationship, you will need to add
178+
it manually into the entity or to the generated ``xml`` or ``yml`` files.
179+
Add a section on the specific entities for ``oneToMany`` defining the
180+
``inversedBy`` and the ``mappedBy`` pieces.
181+
182+
The generated entities are now ready to be used. Have fun!
183183

184184
.. _`Doctrine tools documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html#reverse-engineering

0 commit comments

Comments
 (0)