Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony : What is the meaning of auto_mapping and auto_generate_proxy_classes

The configuration uses :

doctrine:
dbal:
  driver:   "%database_driver%"
   ....
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true

What is the exact meaning of auto_mapping? It is used in tons of examples with true and false, and no precise description. When does occurs the proxy generation if it's not auto ? By doctrine command-line tools ?

like image 952
Nicolas Zozol Avatar asked Nov 17 '14 14:11

Nicolas Zozol


1 Answers

auto_mapping is where doctrine will automatically load the mapping from your bundle Resources/config/doctrine directory.

Setting it to false will mean that you will need to load the mappings yourself. It can be handy if you have mappings for entities rather than mapped superclasses in a vendor bundle that you want to override.

You can do this either by way of stating the mappings in the doctrine config ...

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    AcmeUnknownBundle:
                        mapping:              true
                        type:                 yml
                        dir:                  "Resources/config/doctrine"
                        alias:                ~
                        prefix:               Acme\UnknownBundle\Entity
                        is_bundle:            true

adding them in some sort of mappings pass ...

class AcmeUnknownBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);
        // ...

        $modelDir = realpath(__DIR__.'/Resources/config/doctrine/model');
        $mappings = array(
            $modelDir => 'Acme\UnknownBundle\Model',
        );

        $ormCompilerClass = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
        if (class_exists($ormCompilerClass)) {
            $container->addCompilerPass(
                DoctrineOrmMappingsPass::createYamlMappingDriver(
                    $mappings,
                    array('acme_unknown.model_manager_name'),
                    true
            ));
        }
    }
}
like image 78
qooplmao Avatar answered Oct 12 '22 23:10

qooplmao