@@ -59,7 +59,6 @@ If you want to enable the Doctrine 2 ORM you can do so with the following:
59
59
60
60
doctrine.orm:
61
61
default_entity_manager: default
62
- metadata_driver: xml # xml, yml, annotation
63
62
cache_driver: apc # array, apc, memcache, xcache
64
63
entity_managers:
65
64
default:
@@ -157,6 +156,8 @@ file named **Entry.php** with some code like the following:
157
156
The Doctrine 2 CLI is integrated with the Symfony 2 CLI so we have all the common
158
157
commands we need to make working with Doctrine 2 just as easy and fast as before!
159
158
159
+ ### Listing Available Doctrine Commands
160
+
160
161
$ php console list doctrine
161
162
162
163
Available commands for the "doctrine" namespace:
@@ -167,12 +168,45 @@ commands we need to make working with Doctrine 2 just as easy and fast as before
167
168
:database-tool Create and drop the configured databases.
168
169
:ensure-production-settings Verify that Doctrine is properly configured for a production environment.
169
170
:generate-proxies Generates proxy classes for entity classes.
171
+ :import-mapping Import the initial mapping information for entities from an existing database.
172
+ :init-entity Initialize a new Doctrine entity inside a bundle.
170
173
:load-data-fixtures Load data fixtures to your database.
171
174
:run-dql Executes arbitrary DQL directly from the command line.
172
175
:run-sql Executes arbitrary SQL from a file or directly from the command line.
173
176
:schema-tool Processes the schema and either apply it directly on EntityManager or generate the SQL output.
174
177
:version Displays the current installed Doctrine version.
175
178
179
+ ### Schema Tool
180
+
181
+ The schema tool in Doctrine 2 allows you to easily drop and your create your
182
+ database schemas for your mapping information.
183
+
184
+ You can easily create your initial schema from mapping information:
185
+
186
+ php console doctrine:schema-tool --create
187
+
188
+ Or if you want to then drop your schema you can do:
189
+
190
+ php console doctrine:schema-tool --drop
191
+
192
+ If you want to re-create it (drop and create) you can use:
193
+
194
+ php console doctrine:schema-tool --re-create
195
+
196
+ Now the scenario arrises where you want to change your mapping information and
197
+ update your database without blowing away everything and losing your existing data.
198
+ You can do the following for that:
199
+
200
+ php console doctrine:schema-tool --update
201
+
202
+ > **TIP**
203
+ > The above will not drop anything from your database schema. To drop the remaining
204
+ > things from your schema you need to use the **--complete-update** option.
205
+ >
206
+ > php console doctrine:schema-tool --complete-update
207
+
208
+ ### Doctrine Build Command
209
+
176
210
The development workflow is very similar to how it is in Symfony 1.4. You can modify
177
211
your mapping information and use **doctrine:build --all** to re-build your
178
212
environment:
@@ -187,6 +221,11 @@ schema:
187
221
Now any changes you made in your mapping information will be reflected in the
188
222
according databases! Here are all the available options for the **build** task:
189
223
224
+ > **NOTE**
225
+ > Not the key difference here is that you can modify your schema during development
226
+ > and just update your database schema without having to blow everything away and
227
+ > re-build it all.
228
+
190
229
$ php console help doctrine:build
191
230
Usage:
192
231
Symfony doctrine:build [--all] [--all-classes] [--entities] [--db] [--and-load[="..."]] [--and-append[="..."]] [--and-update-schema] [--dump-sql] [--connection]
@@ -198,4 +237,20 @@ according databases! Here are all the available options for the **build** task:
198
237
--and-load Load data fixtures (multiple values allowed)
199
238
--and-append Load data fixtures and append to existing data (multiple values allowed)
200
239
--and-update-schema Update schema after rebuilding all classes
201
- --connection The connection to use.
240
+ --connection The connection to use.
241
+
242
+ ### Doctrine Init Entity Command
243
+
244
+ You can easily initialize a new Doctrine entity for a bundle by using the
245
+ **doctrine:init-bundle** command:
246
+
247
+ $ php console doctrine:init-entity --bundle="Bundle\MySampleBundle" --entity="User\Group"
248
+
249
+ Now if you have a look inside the bundle you will see that you have a **Group** class
250
+ located here **Bundle/MySampleBundle/Entities/User/Group.php**.
251
+
252
+ Now you can customize the mapping information for the entity by editing the metadata
253
+ information inside **Bundle/MySampleBundle/Resources/config/doctrine/metadata** and
254
+ just update your database schema:
255
+
256
+ $ php console doctrine:schema-tool --update
0 commit comments