@@ -64,60 +64,55 @@ tables fields.
64
64
65
65
This command line tool asks Doctrine to introspect the database and generate
66
66
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 ``.
68
69
69
70
.. tip ::
70
71
71
72
It's also possible to generate metadata class in YAML format by changing the
72
- first argument to `yml `.
73
+ first argument to `` yml ` `.
73
74
74
75
The generated ``BlogPost.orm.xml `` metadata file looks as follows:
75
76
76
77
.. code-block :: xml
77
78
78
79
<?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 " >
80
81
<entity name =" BlogPost" table =" blog_post" >
81
- <change-tracking-policy >DEFERRED_IMPLICIT</change-tracking-policy >
82
82
<id name =" id" type =" bigint" column =" id" >
83
83
<generator strategy =" IDENTITY" />
84
84
</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" />
92
88
</entity >
93
89
</doctrine-mapping >
94
90
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:
96
93
97
94
.. code-block :: xml
98
95
99
- <entity name =" Acme\BlogBundle\BlogPost" table =" blog_post" >
96
+ <entity name =" Acme\BlogBundle\Entity\ BlogPost" table =" blog_post" >
100
97
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.
109
100
110
101
.. code-block :: bash
111
102
112
103
$ php app/console doctrine:mapping:convert annotation ./src
113
104
$ php app/console doctrine:generate:entities AcmeBlogBundle
114
105
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 ::
117
111
118
- .. code-block :: php
112
+ If you want to use annotations, you can safely delete the XML files after
113
+ running these two commands.
119
114
120
- <?php
115
+ For example, the newly created `` BlogComment `` entity class looks as follow::
121
116
122
117
// src/Acme/BlogBundle/Entity/BlogComment.php
123
118
namespace Acme\BlogBundle\Entity;
@@ -133,9 +128,9 @@ The newly created ``BlogComment`` entity class looks as follow:
133
128
class BlogComment
134
129
{
135
130
/**
136
- * @var bigint $id
131
+ * @var integer $id
137
132
*
138
- * @ORM\Column(name="id", type="bigint", nullable=false )
133
+ * @ORM\Column(name="id", type="bigint")
139
134
* @ORM\Id
140
135
* @ORM\GeneratedValue(strategy="IDENTITY")
141
136
*/
@@ -177,8 +172,13 @@ relationship with the ``BlogPost`` entity class based on the foreign key constra
177
172
Consequently, you can find a private ``$post `` property mapped with a ``BlogPost ``
178
173
entity in the ``BlogComment `` entity class.
179
174
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!
183
183
184
184
.. _`Doctrine tools documentation` : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html#reverse-engineering
0 commit comments