1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Fix typos and wording in NamingStrategy documentation

This commit is contained in:
Sven Cannivy 2017-02-10 18:48:57 +01:00
parent 23ae83e351
commit 260c8d0113

View File

@ -3,21 +3,18 @@ Implementing a NamingStrategy
.. versionadded:: 2.3 .. versionadded:: 2.3
Using a naming strategy you can provide rules for automatically generating Using a naming strategy you can provide rules for generating database identifiers,
database identifiers, columns and tables names column or table names when the column or table name is not given. This feature helps
when the table/column name is not given. reduce the verbosity of the mapping document, eliminating repetitive noise (eg: ``TABLE_``).
This feature helps reduce the verbosity of the mapping document,
eliminating repetitive noise (eg: ``TABLE_``).
Configuring a naming strategy Configuring a naming strategy
----------------------------- -----------------------------
The default strategy used by Doctrine is quite minimal. The default strategy used by Doctrine is quite minimal.
By default the ``Doctrine\ORM\Mapping\DefaultNamingStrategy`` By default the ``Doctrine\ORM\Mapping\DefaultNamingStrategy``
uses the simple class name and the attributes names to generate tables and columns uses the simple class name and the attribute names to generate tables and columns.
You can specify a different strategy by calling ``Doctrine\ORM\Configuration#setNamingStrategy()`` : You can specify a different strategy by calling ``Doctrine\ORM\Configuration#setNamingStrategy()``:
.. code-block:: php .. code-block:: php
@ -28,8 +25,7 @@ You can specify a different strategy by calling ``Doctrine\ORM\Configuration#set
Underscore naming strategy Underscore naming strategy
--------------------------- ---------------------------
``\Doctrine\ORM\Mapping\UnderscoreNamingStrategy`` is a built-in strategy ``\Doctrine\ORM\Mapping\UnderscoreNamingStrategy`` is a built-in strategy.
that might be a useful if you want to use a underlying convention.
.. code-block:: php .. code-block:: php
@ -37,14 +33,13 @@ that might be a useful if you want to use a underlying convention.
$namingStrategy = new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER); $namingStrategy = new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER);
$configuration()->setNamingStrategy($namingStrategy); $configuration()->setNamingStrategy($namingStrategy);
Then SomeEntityName will generate the table SOME_ENTITY_NAME when CASE_UPPER For SomeEntityName the strategy will generate the table SOME_ENTITY_NAME with the
or some_entity_name using CASE_LOWER is given. ``CASE_UPPER`` option, or some_entity_name with the ``CASE_LOWER`` option.
Naming strategy interface Naming strategy interface
------------------------- -------------------------
The interface ``Doctrine\ORM\Mapping\NamingStrategy`` allows you to specify The interface ``Doctrine\ORM\Mapping\NamingStrategy`` allows you to specify
a "naming standard" for database tables and columns. a naming strategy for database tables and columns.
.. code-block:: php .. code-block:: php
@ -101,10 +96,11 @@ a "naming standard" for database tables and columns.
Implementing a naming strategy Implementing a naming strategy
------------------------------- -------------------------------
If you have database naming standards like all tables names should be prefixed If you have database naming standards, like all table names should be prefixed
by the application prefix, all column names should be upper case, by the application prefix, all column names should be upper case, you can easily
you can easily achieve such standards by implementing a naming strategy. achieve such standards by implementing a naming strategy.
You need to implements NamingStrategy first. Following is an example
You need to create a class which implements ``Doctrine\ORM\Mapping\NamingStrategy``.
.. code-block:: php .. code-block:: php
@ -139,12 +135,3 @@ You need to implements NamingStrategy first. Following is an example
($referencedColumnName ?: $this->referenceColumnName())); ($referencedColumnName ?: $this->referenceColumnName()));
} }
} }
Configuring the namingstrategy is easy if.
Just set your naming strategy calling ``Doctrine\ORM\Configuration#setNamingStrategy()`` :.
.. code-block:: php
<?php
$namingStrategy = new MyAppNamingStrategy();
$configuration()->setNamingStrategy($namingStrategy);