@@ -109,16 +109,10 @@ The following Commands are currently available:
109
109
cache drivers.
110
110
- ``orm:convert-d1-schema `` Converts Doctrine 1.X schema into a
111
111
Doctrine 2.X schema.
112
- - ``orm:convert-mapping `` Convert mapping information between
113
- supported formats.
114
112
- ``orm:ensure-production-settings `` Verify that Doctrine is
115
113
properly configured for a production environment.
116
- - ``orm:generate-entities `` Generate entity classes and method
117
- stubs from your mapping information.
118
114
- ``orm:generate-proxies `` Generates proxy classes for entity
119
115
classes.
120
- - ``orm:generate-repositories `` Generate repository classes from
121
- your mapping information.
122
116
- ``orm:run-dql `` Executes arbitrary DQL directly from the command
123
117
line.
124
118
- ``orm:schema-tool:create `` Processes the schema and either
@@ -135,10 +129,7 @@ For these commands are also available aliases:
135
129
136
130
137
131
- ``orm:convert:d1-schema `` is alias for ``orm:convert-d1-schema ``.
138
- - ``orm:convert:mapping `` is alias for ``orm:convert-mapping ``.
139
- - ``orm:generate:entities `` is alias for ``orm:generate-entities ``.
140
132
- ``orm:generate:proxies `` is alias for ``orm:generate-proxies ``.
141
- - ``orm:generate:repositories `` is alias for ``orm:generate-repositories ``.
142
133
143
134
.. note ::
144
135
@@ -261,162 +252,6 @@ your cli-config.php properly.
261
252
(or mapping files), i.e.
262
253
``new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em, $mappingPaths); ``
263
254
264
- Entity Generation
265
- -----------------
266
-
267
- Generate entity classes and method stubs from your mapping information.
268
-
269
- .. code-block :: php
270
-
271
- $ php doctrine orm:generate-entities
272
- $ php doctrine orm:generate-entities --update-entities
273
- $ php doctrine orm:generate-entities --regenerate-entities
274
-
275
- This command is not suited for constant usage. It is a little helper and does
276
- not support all the mapping edge cases very well. You still have to put work
277
- in your entities after using this command.
278
-
279
- It is possible to use the EntityGenerator on code that you have already written. It will
280
- not be lost. The EntityGenerator will only append new code to your
281
- file and will not delete the old code. However this approach may still be prone
282
- to error and we suggest you use code repositories such as GIT or SVN to make
283
- backups of your code.
284
-
285
- It makes sense to generate the entity code if you are using entities as Data
286
- Access Objects only and don't put much additional logic on them. If you are
287
- however putting much more logic on the entities you should refrain from using
288
- the entity-generator and code your entities manually.
289
-
290
- .. note ::
291
-
292
- Even if you specified Inheritance options in your
293
- XML or YAML Mapping files the generator cannot generate the base and
294
- child classes for you correctly, because it doesn't know which
295
- class is supposed to extend which. You have to adjust the entity
296
- code manually for inheritance to work!
297
-
298
-
299
- Convert Mapping Information
300
- ---------------------------
301
-
302
- Convert mapping information between supported formats.
303
-
304
- This is an **execute one-time ** command. It should not be necessary for
305
- you to call this method multiple times, especially when using the ``--from-database ``
306
- flag.
307
-
308
- Converting an existing database schema into mapping files only solves about 70-80%
309
- of the necessary mapping information. Additionally the detection from an existing
310
- database cannot detect inverse associations, inheritance types,
311
- entities with foreign keys as primary keys and many of the
312
- semantical operations on associations such as cascade.
313
-
314
- .. note ::
315
-
316
- There is no need to convert YAML or XML mapping files to annotations
317
- every time you make changes. All mapping drivers are first class citizens
318
- in Doctrine 2 and can be used as runtime mapping for the ORM. See the
319
- docs on XML and YAML Mapping for an example how to register this metadata
320
- drivers as primary mapping source.
321
-
322
- To convert some mapping information between the various supported
323
- formats you can use the ``ClassMetadataExporter `` to get exporter
324
- instances for the different formats:
325
-
326
- .. code-block :: php
327
-
328
- <?php
329
- $cme = new \Doctrine\ORM\Tools\Export\ClassMetadataExporter();
330
-
331
- Once you have a instance you can use it to get an exporter. For
332
- example, the yml exporter:
333
-
334
- .. code-block :: php
335
-
336
- <?php
337
- $exporter = $cme->getExporter('yml', '/path/to/export/yml');
338
-
339
- Now you can export some ``ClassMetadata `` instances:
340
-
341
- .. code-block :: php
342
-
343
- <?php
344
- $classes = array(
345
- $em->getClassMetadata('Entities\User'),
346
- $em->getClassMetadata('Entities\Profile')
347
- );
348
- $exporter->setMetadata($classes);
349
- $exporter->export();
350
-
351
- This functionality is also available from the command line to
352
- convert your loaded mapping information to another format. The
353
- ``orm:convert-mapping `` command accepts two arguments, the type to
354
- convert to and the path to generate it:
355
-
356
- .. code-block :: php
357
-
358
- $ php doctrine orm:convert-mapping xml /path/to/mapping-path-converted-to-xml
359
-
360
- Reverse Engineering
361
- -------------------
362
-
363
- You can use the ``DatabaseDriver `` to reverse engineer a database
364
- to an array of ``ClassMetadata `` instances and generate YAML, XML, etc. from them.
365
-
366
- .. note ::
367
-
368
- Reverse Engineering is a **one-time ** process that can get you started with a project.
369
- Converting an existing database schema into mapping files only detects about 70-80%
370
- of the necessary mapping information. Additionally the detection from an existing
371
- database cannot detect inverse associations, inheritance types,
372
- entities with foreign keys as primary keys and many of the
373
- semantical operations on associations such as cascade.
374
-
375
- First you need to retrieve the metadata instances with the
376
- ``DatabaseDriver ``:
377
-
378
- .. code-block :: php
379
-
380
- <?php
381
- $em->getConfiguration()->setMetadataDriverImpl(
382
- new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
383
- $em->getConnection()->getSchemaManager()
384
- )
385
- );
386
-
387
- $cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
388
- $cmf->setEntityManager($em);
389
- $metadata = $cmf->getAllMetadata();
390
-
391
- Now you can get an exporter instance and export the loaded metadata
392
- to yml:
393
-
394
- .. code-block :: php
395
-
396
- <?php
397
- $cme = new \Doctrine\ORM\Tools\Export\ClassMetadataExporter();
398
- $exporter = $cme->getExporter('yml', '/path/to/export/yml');
399
- $exporter->setMetadata($metadata);
400
- $exporter->export();
401
-
402
- You can also reverse engineer a database using the
403
- ``orm:convert-mapping `` command:
404
-
405
- .. code-block :: php
406
-
407
- $ php doctrine orm:convert-mapping --from-database yml /path/to/mapping-path-converted-to-yml
408
-
409
- .. note ::
410
-
411
- Reverse Engineering is not always working perfectly
412
- depending on special cases. It will only detect Many-To-One
413
- relations (even if they are One-To-One) and will try to create
414
- entities from Many-To-Many tables. It also has problems with naming
415
- of foreign keys that have multiple column names. Any Reverse
416
- Engineered Database-Schema needs considerable manual work to become
417
- a useful domain model.
418
-
419
-
420
255
Runtime vs Development Mapping Validation
421
256
-----------------------------------------
422
257
0 commit comments