[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.147.195.28: ~ $
SQL-Table Prefixes
==================

This recipe is intended as an example of implementing a
loadClassMetadata listener to provide a Table Prefix option for
your application. The method used below is not a hack, but fully
integrates into the Doctrine system, all SQL generated will include
the appropriate table prefix.

In most circumstances it is desirable to separate different
applications into individual databases, but in certain cases, it
may be beneficial to have a table prefix for your Entities to
separate them from other vendor products in the same database.

Implementing the listener
-------------------------

The listener in this example has been set up with the
DoctrineExtensions namespace. You create this file in your
library/DoctrineExtensions directory, but will need to set up
appropriate autoloaders.

.. code-block:: php

    <?php
    
    namespace DoctrineExtensions;
    use \Doctrine\ORM\Event\LoadClassMetadataEventArgs;
    
    class TablePrefix
    {
        protected $prefix = '';
    
        public function __construct($prefix)
        {
            $this->prefix = (string) $prefix;
        }
    
        public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
        {
            $classMetadata = $eventArgs->getClassMetadata();

            if (!$classMetadata->isInheritanceTypeSingleTable() || $classMetadata->getName() === $classMetadata->rootEntityName) {
                $classMetadata->setPrimaryTable([
                    'name' => $this->prefix . $classMetadata->getTableName()
                ]);
            }

            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
                if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY && $mapping['isOwningSide']) {
                    $mappedTableName = $mapping['joinTable']['name'];
                    $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName;
                }
            }
        }

    }

Telling the EntityManager about our listener
--------------------------------------------

A listener of this type must be set up before the EntityManager has
been initialised, otherwise an Entity might be created or cached
before the prefix has been set.

.. note::

    If you set this listener up, be aware that you will need
    to clear your caches and drop then recreate your database schema.


.. code-block:: php

    <?php
    
    // $connectionOptions and $config set earlier
    
    $evm = new \Doctrine\Common\EventManager;
    
    // Table Prefix
    $tablePrefix = new \DoctrineExtensions\TablePrefix('prefix_');
    $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
    
    $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $evm);



Filemanager

Name Type Size Permission Actions
advanced-field-value-conversion-using-custom-mapping-types.rst File 7.07 KB 0644
aggregate-fields.rst File 11.41 KB 0644
custom-mapping-types.rst File 3.04 KB 0644
decorator-pattern.rst File 6.65 KB 0644
dql-custom-walkers.rst File 7.75 KB 0644
dql-user-defined-functions.rst File 9.39 KB 0644
entities-in-session.rst File 2.29 KB 0644
implementing-arrayaccess-for-domain-objects.rst File 3.06 KB 0644
implementing-the-notify-changetracking-policy.rst File 2.36 KB 0644
implementing-wakeup-or-clone.rst File 2.23 KB 0644
integrating-with-codeigniter.rst File 4.18 KB 0644
mysql-enums.rst File 5.79 KB 0644
resolve-target-entity-listener.rst File 4.4 KB 0644
sql-table-prefixes.rst File 2.78 KB 0644
strategy-cookbook-introduction.rst File 8.54 KB 0644
validation-of-entities.rst File 4.31 KB 0644
working-with-datetime.rst File 6.57 KB 0644