@@ -62,16 +62,44 @@ information. By convention, this information is usually configured in an
62
62
The parameters defined in that file are referenced by the main configuration
63
63
file when setting up Doctrine:
64
64
65
- .. code-block :: yaml
66
-
67
- # app/config/config.yml
68
- doctrine :
69
- dbal :
70
- driver : " %database_driver%"
71
- host : " %database_host%"
72
- dbname : " %database_name%"
73
- user : " %database_user%"
74
- password : " %database_password%"
65
+ .. configuration-block ::
66
+
67
+ .. code-block :: yaml
68
+
69
+ # app/config/config.yml
70
+ doctrine :
71
+ dbal :
72
+ driver : " %database_driver%"
73
+ host : " %database_host%"
74
+ dbname : " %database_name%"
75
+ user : " %database_user%"
76
+ password : " %database_password%"
77
+
78
+ .. code-block :: xml
79
+
80
+ <!-- app/config/config.xml -->
81
+ <doctrine : config >
82
+ <doctrine : dbal
83
+ driver =" %database_driver%"
84
+ host =" %database_host%"
85
+ dbname =" %database_name%"
86
+ user =" %database_user%"
87
+ password =" %database_password%"
88
+ >
89
+ </doctrine : config >
90
+
91
+ .. code-block :: php
92
+
93
+ // app/config/config.php
94
+ $configuration->loadFromExtension('doctrine', array(
95
+ 'dbal' => array(
96
+ 'driver' => '%database_driver%',
97
+ 'host' => '%database_host%',
98
+ 'dbname' => '%database_name%',
99
+ 'user' => '%database_user%',
100
+ 'password' => '%database_password%',
101
+ ),
102
+ ));
75
103
76
104
By separating the database information into a separate file, you can
77
105
easily keep different versions of the file on each server. You can also
@@ -909,6 +937,24 @@ To relate the ``Category`` and ``Product`` entities, start by creating a
909
937
mappedBy : category
910
938
# don't forget to init the collection in entity __construct() method
911
939
940
+ .. code-block :: xml
941
+
942
+ <!-- src/Acme/StoreBundle/Resources/config/doctrine/Category.orm.xml -->
943
+ <doctrine-mapping xmlns =" http://doctrine-project.org/schemas/orm/doctrine-mapping"
944
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
945
+ xsi : schemaLocation =" http://doctrine-project.org/schemas/orm/doctrine-mapping
946
+ http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" >
947
+
948
+ <entity name =" Acme\StoreBundle\Entity\Category" >
949
+ <!-- ... -->
950
+ <one-to-many field =" products"
951
+ target-entity =" product"
952
+ mapped-by =" category"
953
+ />
954
+
955
+ <!-- don't forget to init the collection in entity __construct() method -->
956
+ </entity >
957
+ </doctrine-mapping >
912
958
913
959
First, since a ``Category `` object will relate to many ``Product `` objects,
914
960
a ``products `` array property is added to hold those ``Product `` objects.
@@ -966,6 +1012,28 @@ object, you'll want to add a ``$category`` property to the ``Product`` class:
966
1012
name : category_id
967
1013
referencedColumnName : id
968
1014
1015
+ .. code-block :: xml
1016
+
1017
+ <!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->
1018
+ <doctrine-mapping xmlns =" http://doctrine-project.org/schemas/orm/doctrine-mapping"
1019
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1020
+ xsi : schemaLocation =" http://doctrine-project.org/schemas/orm/doctrine-mapping
1021
+ http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" >
1022
+
1023
+ <entity name =" Acme\StoreBundle\Entity\Product" >
1024
+ <!-- ... -->
1025
+ <many-to-one field =" category"
1026
+ target-entity =" products"
1027
+ join-column =" category"
1028
+ >
1029
+ <join-column
1030
+ name =" category_id"
1031
+ referenced-column-name =" id"
1032
+ />
1033
+ </many-to-one >
1034
+ </entity >
1035
+ </doctrine-mapping >
1036
+
969
1037
Finally, now that you've added a new property to both the ``Category `` and
970
1038
``Product `` classes, tell Doctrine to generate the missing getter and setter
971
1039
methods for you:
@@ -1387,6 +1455,21 @@ and ``nullable``. Take a few examples:
1387
1455
length : 150
1388
1456
unique : true
1389
1457
1458
+ .. code-block :: xml
1459
+
1460
+ <!--
1461
+ A string field length 255 that cannot be null
1462
+ (reflecting the default values for the "length" and *nullable* options)
1463
+ type attribute is necessary in yaml definitions
1464
+ -->
1465
+ <field name =" name" type =" string" />
1466
+ <field name =" email"
1467
+ type =" string"
1468
+ column =" email_address"
1469
+ length =" 150"
1470
+ unique =" true"
1471
+ />
1472
+
1390
1473
.. note ::
1391
1474
1392
1475
There are a few more options not listed here. For more details, see
0 commit comments