lumberjacked
lumberjacked

Reputation: 976

Cannot generate zf2 DoctrineORMModule entities from mapping files

I have zf2 DoctrineORMModule and DoctrienModule installed. I am trying to use the command tool to create mapping files and generate entities from these mapping files. (I know this isn't the preferred method, but this is how I'm going to do it. I have my reasons.)

I have a restful module configured and here is my Doctrine Configuration for this module.

// Doctrine config
    'doctrine' => array(
        'driver' => array(
            'Restful_driver' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Restful/Entities')
            ),
            'orm_default' => array(
                'drivers' => array(
                    'Restful\Entities' => 'Restful_driver'
                )
            )
        )
    )

I first run

doctrine orm:convert-mapping xml /to/my/dest/path --from-database --force

This will create my xml file with all the table info. This part works fine and I can view the xml that it created. Next I try to run

doctrine orm:generate-entities /to/my/dest/path --generate-annotations 
--generate-methods

I don't get any errors but also I don't get any results either. The output from the previous command is.

No Metadata Classes to process.

I have tried to read around but havn't found any articles that really solve my problem. Most say something about not having my annotations/mappings not configured correctly. But I can dump the entity manager through a controller.

var_dump($this->getServiceLocator()->get('doctrine.entitymanager.orm_default'));

What do I need to do to get this to generate entities from xml mappings? Any help is appreciated.

Upvotes: 3

Views: 3372

Answers (3)

ACNB
ACNB

Reputation: 846

I had a similar problem with YAML files and posted my solution here. I'm sure this will work with xml files as well. Just try to add

$driverImpl = new \Doctrine\ORM\Mapping\Driver\XmlDriver(array("YOUR_PATH_TO_XML_FILES"));
/* @var $em \Doctrine\ORM\EntityManager */
$em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
$em->getConfiguration()->setMetadataDriverImpl($driverImpl);

to the doctrine-module.php.

Upvotes: 5

Anton
Anton

Reputation: 1

This "error" occured because you use Annotation Driver for generating. This driver uses your current exist entities and doesnt look at xml. If you want to create Entities from XML - you should send to DI in doctrine configuration section XML driver with need path.

I use another zf2 doctrine module and my DI config has another format, so i cant to send you properly DI example.

Upvotes: 0

briangallagher
briangallagher

Reputation: 539

Did you try using the doctrine-module script in vendor/bin? It should be all set up already to read your app's configs.

./doctrine-module orm:generate-entities ~/doctrine-entities

Upvotes: 0

Related Questions