From 3076e2a1f7828f80a70f5cce0a7d24a132fdd175 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 12 Apr 2012 22:39:39 -0300 Subject: [PATCH] docs for NamingStrategy --- en/index.rst | 3 + en/reference/namingstrategy.rst | 141 ++++++++++++++++++++++++++++++++ en/toc.rst | 3 + 3 files changed, 147 insertions(+) create mode 100644 en/reference/namingstrategy.rst diff --git a/en/index.rst b/en/index.rst index a02f80f55..3841e0654 100644 --- a/en/index.rst +++ b/en/index.rst @@ -84,6 +84,9 @@ Advanced Topics * **Filtering entities**: :doc:`Filters ` +* **Implementing a NamingStrategy**: + :doc:`NamingStrategy ` + * **Performance**: :doc:`Improving Performance ` | :doc:`Caching ` | diff --git a/en/reference/namingstrategy.rst b/en/reference/namingstrategy.rst new file mode 100644 index 000000000..9963fc798 --- /dev/null +++ b/en/reference/namingstrategy.rst @@ -0,0 +1,141 @@ +Implementing a NamingStrategy +============================== + +Using a naming strategy you can provide rules for automatically generating database identifiers, columns and tables names +when the table/column name is not given. +This feature helps reduce the verbosity of the mapping document, eliminating repetitive noise (eg: ``TABLE_``). + + +Configuring a naming strategy +----------------------------- +The default strategy used by Doctrine is quite minimal. + +By default the ``Doctrine\ORM\Mapping\DefaultNamingStrategy`` +uses the simple class name and the attributes names to generate tables and columns + +You can specify a different strategy by calling ``Doctrine\ORM\Configuration#setNamingStrategy()`` : + +.. code-block:: php + + setNamingStrategy($namingStrategy); + +Underscore naming 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 + + setNamingStrategy(namingStrategy); + +Then SomeEntityName will generate the table SOME_ENTITY_NAME when CASE_UPPER or some_entity_name using CASE_LOWER is given. + + +Naming strategy interface +------------------------- +The interface ``Doctrine\ORM\Mapping\NamingStrategy`` allows you to specify a "naming standard" for database tables and columns. + +.. code-block:: php + + referenceColumnName(); + } + public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) + { + return strtolower($this->classToTableName($sourceEntity) . '_' . + $this->classToTableName($targetEntity)); + } + public function joinKeyColumnName($entityName, $referencedColumnName = null) + { + return strtolower($this->classToTableName($entityName) . '_' . + ($referencedColumnName ?: $this->referenceColumnName())); + } + } + +Configuring the namingstrategy is easy if. +Just set your naming strategy calling ``Doctrine\ORM\Configuration#setNamingStrategy()`` :. + +.. code-block:: php + + setNamingStrategy($namingStrategy); \ No newline at end of file diff --git a/en/toc.rst b/en/toc.rst index 8178f8c05..5cdbe90c7 100644 --- a/en/toc.rst +++ b/en/toc.rst @@ -50,6 +50,9 @@ Reference Guide reference/metadata-drivers reference/best-practices reference/limitations-and-known-issues + tutorials/pagination.rst + reference/filters.rst + reference/namingstrategy.rst Cookbook