Skip to content

Commit 18d7123

Browse files
committed
[cookbook][doctrine] Updated the cookbook entry about custom types
1 parent c8fec39 commit 18d7123

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

cookbook/doctrine/dbal.rst

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ with the most popular relational databases. In other words, the DBAL library
1717
makes it easy to execute queries and perform other database actions.
1818

1919
.. tip::
20-
20+
2121
Read the official Doctrine `DBAL Documentation`_ to learn all the details
2222
and capabilities of Doctrine's DBAL library.
2323

@@ -37,7 +37,7 @@ To get started, configure the database connection parameters:
3737
charset: UTF8
3838
3939
.. code-block:: xml
40-
40+
4141
// app/config/config.xml
4242
<doctrine:config>
4343
<doctrine:dbal
@@ -97,6 +97,63 @@ mapping types, read Doctrine's `Custom Mapping Types`_ section of their document
9797
custom_first: Acme\HelloBundle\Type\CustomFirst
9898
custom_second: Acme\HelloBundle\Type\CustomSecond
9999
100+
.. code-block:: xml
101+
102+
<!-- app/config/config.xml -->
103+
<container xmlns="http://symfony.com/schema/dic/services"
104+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
105+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
106+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
107+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
108+
109+
<doctrine:config>
110+
<doctrine:dbal>
111+
<doctrine:dbal default-connection="default">
112+
<doctrine:connection>
113+
<doctrine:mapping-type name="enum">string</doctrine:mapping-type>
114+
</doctrine:connection>
115+
</doctrine:dbal>
116+
</doctrine:config>
117+
</container>
118+
119+
.. code-block:: php
120+
121+
// app/config/config.php
122+
$container->loadFromExtension('doctrine', array(
123+
'dbal' => array(
124+
'connections' => array(
125+
'default' => array(
126+
'mapping_types' => array(
127+
'enum' => 'string',
128+
),
129+
),
130+
),
131+
),
132+
));
133+
134+
Registering Custom Mapping Types in the SchemaTool
135+
--------------------------------------------------
136+
137+
The SchemaTool is used to inspect the database to compare the schema. To
138+
achieve this task, it needs to know which mapping type needs to be used
139+
for each database types. Registering new ones can be done through the configuration.
140+
141+
Let's map the ENUM type (not suppoorted by DBAL by default) to a the ``string``
142+
mapping type:
143+
144+
.. configuration-block::
145+
146+
.. code-block:: yaml
147+
148+
# app/config/config.yml
149+
doctrine:
150+
dbal:
151+
connection:
152+
default:
153+
// Other connections parameters
154+
mapping_types:
155+
enum: string
156+
100157
.. code-block:: xml
101158
102159
<!-- app/config/config.xml -->
@@ -115,7 +172,7 @@ mapping types, read Doctrine's `Custom Mapping Types`_ section of their document
115172
</container>
116173
117174
.. code-block:: php
118-
175+
119176
// app/config/config.php
120177
$container->loadFromExtension('doctrine', array(
121178
'dbal' => array(

0 commit comments

Comments
 (0)