Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2: Generated entities from database don't have namespaces

I am creating entities from the database trough the \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory() class. This works perfectly! Except for the namespace generation. There are no namespaces generated. I am storing my entities in App/Model/Entities.

Does anyone know how to make the generator add namespaces to the entities?

This is the code I use to generate the entities:

<?php
$em->getConfiguration()->setMetadataDriverImpl(
    new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
        $em->getConnection()->getSchemaManager()
    )
);

$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();

// GENERATE PHP ENTITIES!
$entityGenerator = new \Doctrine\ORM\Tools\EntityGenerator(); 
$entityGenerator->setGenerateAnnotations(true); 
$entityGenerator->setGenerateStubMethods(true); 
$entityGenerator->setRegenerateEntityIfExists(false); 
$entityGenerator->setUpdateEntityIfExists(true); 
$entityGenerator->generate($metadata, __dir__. '/Model/Entities");
like image 568
mmmmm Avatar asked Sep 26 '12 11:09

mmmmm


1 Answers

I think, the better way is set namespace directly to driver

<?php
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager());
$driver->setNamespace('App\\Model\\Entities\\');

$em->getConfiguration()->setMetadataDriverImpl($driver);

....
like image 153
leninzprahy Avatar answered Sep 19 '22 05:09

leninzprahy