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