Thanks.
Hidding Entities help to
make
http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html
this example working.
If you using same table for AppBundle\Entity\Customer as
UserBundle\Entity\Customer, ResolveTargetEntityListener will be working.
But symfony console will not create/update/drop schemas, because two
entities use same table. (Parent and app Customer)
But if you set to ignore your app Customer entity for all three operations
, listener will work, and doctrine:schema:COMMANDs will work too.
суббота, 20 сентября 2014 г., 15:41:34 UTC+3 пользователь Alexandru
Trandafir Catalin написал:
>
> Just found the solution myself, adding it here and also on Stackoverflow:
>
> The problem was I was extending the wrong class. Because symfony is not
> using Doctrine's original command at:
> \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand
>
> Instead it uses the one from the bundle, located at:
> \Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand
>
> So basically the end result would
> be src/Webscoming/CoreBundle/Command/DoctrineUpdateCommand.php:
>
> <?php
>
>
> namespace Webscoming\CoreBundle\Command;
>
>
> use Symfony\Component\Console\Input\InputOption;
> use Symfony\Component\Console\Input\InputArgument;
> use Symfony\Component\Console\Input\InputInterface;
> use Symfony\Component\Console\Output\OutputInterface;
> use Doctrine\ORM\Tools\SchemaTool;
>
>
> class DoctrineUpdateCommand extends \Doctrine\Bundle\DoctrineBundle\
> Command\Proxy\UpdateSchemaDoctrineCommand {
>
>
> protected $ignoredEntities = array(
> 'Webscoming\CoreBundle\Entity\AuctionExpress'
> );
>
>
> protected function executeSchemaCommand(InputInterface $input,
> OutputInterface $output, SchemaTool $schemaTool, array $metadatas) {
>
> /** @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
> $newMetadatas = array();
> foreach ($metadatas as $metadata) {
> if (!in_array($metadata->getName(), $this->ignoredEntities)) {
> array_push($newMetadatas, $metadata);
> }
> }
>
>
> parent::executeSchemaCommand($input, $output, $schemaTool,
> $newMetadatas);
> }
>
>
> }
>
>
> Hope it helps someone! I've lost a couple of hours to figure this.
>
> On Saturday, September 20, 2014 2:22:24 PM UTC+2, Alexandru Trandafir
> Catalin wrote:
>>
>> Hey there,
>>
>> I'm trying to extend the update command of doctrine in Symfony2 and I get
>> this error:
>> [InvalidArgumentException]
>> The helper "em" is not defined.
>>
>> The code I've got is this:
>>
>> In src/Webscoming/CoreBundle/Command/DoctrineUpdateCommand.php:
>>
>> <?php
>>
>>
>> namespace Webscoming\CoreBundle\Command;
>>
>>
>> use Symfony\Component\Console\Input\InputOption;
>> use Symfony\Component\Console\Input\InputArgument;
>> use Symfony\Component\Console\Input\InputInterface;
>> use Symfony\Component\Console\Output\OutputInterface;
>> use Doctrine\ORM\Tools\SchemaTool;
>>
>>
>> class DoctrineUpdateCommand extends \Doctrine\ORM\Tools\Console\Command\
>> SchemaTool\UpdateCommand {
>>
>>
>> protected $name = 'orm:schema-tool:myupdate';
>> protected $ignoredEntities = array(
>> 'Entity\Asset\Name'
>> );
>>
>>
>> protected function executeSchemaCommand(InputInterface $input,
>> OutputInterface $output, SchemaTool $schemaTool, array $metadatas) {
>> /** @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
>> $newMetadatas = array();
>> foreach ($metadatas as $metadata) {
>> if (!in_array($metadata->getName(), $this->ignoredEntities)) {
>> array_push($newMetadatas, $metadata);
>> }
>> }
>>
>>
>> parent::executeSchemaCommand($input, $output, $schemaTool,
>> $newMetadatas);
>> }
>>
>>
>> }
>>
>> Any idea what am I missing? I'm following this post on Stackoverflow but
>> it seems I'm doing something wrong:
>>
>> http://stackoverflow.com/questions/12563005/ignore-a-doctrine2-entity-when-running-schema-manager-update
>>
>> Thanks!
>>
>> On Tuesday, September 25, 2012 9:53:17 AM UTC+2, Marco Pivetta wrote:
>>>
>>> As you can see at
>>> https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php#L45-53
>>>
>>> , the schema-tool CLI command (
>>> https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php
>>>
>>> ) uses all the metadata collected across your mapping drivers.
>>>
>>> If you want to exclude particular classes, you may want to extend
>>> UpdateCommand so that it picks only metadata suiting your needs.
>>>
>>> You can then attach your command to your CLI and use that one instead of
>>> the one packaged with Doctrine2
>>>
>>> Marco Pivetta
>>>
>>> http://twitter.com/Ocramius
>>>
>>> http://marco-pivetta.com
>>>
>>>
>>>
>>> On 25 September 2012 09:42, Chris Ramakers <[email protected]> wrote:
>>>
>>>> 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
>>>> commandline 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, ...)? Or
>>>> is it possible to do this with a plugin, listener, ...?
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "doctrine-user" group.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msg/doctrine-user/-/8Gs3ZUwvob8J.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/doctrine-user?hl=en.
>>>>
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.