I've got a Doctrine Entity defined that maps to a View in my database. All works fine, the Entity relations work fine as expected.
Problem now is that when running orm:schema-manager:update
on the CLI a table gets created for this entity which is something I want to prevent. There already is a view for this Entity, no need to create a table for it.
Can I annotate the Entity so that a table won't be created while still keeping access to all Entity related functionality (associations, ...)?
$schema->getTableNames()
was not working (I don't know why).So:
And Register a service
Worked fine! ;)
Eventually it was fairly simple, I just had to subclass the
\Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand
into my own CLI Command. In that subclass filter the$metadatas
array that's being passed toexecuteSchemaCommand()
and then pass it on to the parent function.Just attach this new subclassed command to the ConsoleApplication you are using in your doctrine cli script and done!
Below is the extended command, in production you'll probably want to fetch the
$ignoredEntities
property from you config or something, this should put you on the way.PS: credits go to Marco Pivetta for putting me on the right track. https://groups.google.com/forum/?fromgroups=#!topic/doctrine-user/rwWXZ7faPsA
Quite old one but there is also worth nothing solution using
Doctrine2
:postGenerateSchema
event listener - for me it's better than overridingDoctrine
classes:Also register listener:
No extra hooks is necessary.
If problem is only with producing errors in db_view, when calling doctrine:schema:update command, why not simplest way:
;-)
Based on the original alswer of ChrisR inspired in Marco Pivetta's post I'm adding here the solution if you're using Symfony2:
Looks like Symfony2 doesn't use the original Doctrine command at: \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand
Instead it uses the one in the bundle: \Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand
So basically that is the class that must be extended, ending up in having:
src/Acme/CoreBundle/Command/DoctrineUpdateCommand.php: