Skip to content

Commit bdebbdf

Browse files
committed
[Book/doctrine] Added missing formats
1 parent 91b440c commit bdebbdf

File tree

1 file changed

+93
-10
lines changed

1 file changed

+93
-10
lines changed

book/doctrine.rst

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,44 @@ information. By convention, this information is usually configured in an
6262
The parameters defined in that file are referenced by the main configuration
6363
file when setting up Doctrine:
6464

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+
));
75103
76104
By separating the database information into a separate file, you can
77105
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
909937
mappedBy: category
910938
# don't forget to init the collection in entity __construct() method
911939
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>
912958
913959
First, since a ``Category`` object will relate to many ``Product`` objects,
914960
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:
9661012
name: category_id
9671013
referencedColumnName: id
9681014
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+
9691037
Finally, now that you've added a new property to both the ``Category`` and
9701038
``Product`` classes, tell Doctrine to generate the missing getter and setter
9711039
methods for you:
@@ -1387,6 +1455,21 @@ and ``nullable``. Take a few examples:
13871455
length: 150
13881456
unique: true
13891457
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+
13901473
.. note::
13911474

13921475
There are a few more options not listed here. For more details, see

0 commit comments

Comments
 (0)