gpt4 book ai didi

doctrine-orm - 运行模式管理器更新时忽略 Doctrine2 实体

转载 作者:行者123 更新时间:2023-12-04 02:46:09 27 4
gpt4 key购买 nike

我定义了一个 Doctrine 实体,它映射到我的数据库中的一个 View 。一切正常,实体关系按预期正常工作。

现在的问题是运行时orm:schema-manager:update在 CLI 上为该实体创建了一个表,这是我想阻止的。这个实体已经有一个 View ,不需要为它创建一个表。

我可以注释实体以便在保持对所有实体相关功能(关联,...)的访问的同时不会创建表吗?

最佳答案

基于受到 Marco Pivetta 帖子启发的 ChrisR 的原始 alswer,如果您使用的是 Symfony2,我将在此处添加解决方案:

看起来 Symfony2 没有在以下位置使用原始的 Doctrine 命令:
\Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand

相反,它使用捆绑包中的一个:
\Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand

所以基本上这是必须扩展的类,最终具有:

src/Acme/CoreBundle/Command/DoctrineUpdateCommand.php:

<?php

namespace Acme\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(
'Acme\CoreBundle\Entity\EntityToIgnore'
);

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);
}

}

关于doctrine-orm - 运行模式管理器更新时忽略 Doctrine2 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12563005/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com