好吧,我不知道如何修复项目中的错误。
我正在尝试处理具有多对多属性关系的嵌套表单。
错误表明它无法创建关联,因为其中一侧需要 ID。
好吧。所以我尝试只创建缺失的一面。
但仍然是同样的错误。
最后,我意识到这个简单的代码仍然存在同样的问题:
public function onSuccess(Page $page)
{
$this->em->flush();
}
我希望收到一条错误消息,例如“嘿,没有什么可以刷新的!”
但不,仍然是同样的错误:我必须在关联它之前创建对象(及其 id)。
我查看了堆栈跟踪。是的,似乎 UnitOfWork ->computeAssociationChanges 在刷新之后被调用,并且需要关联对象的 Id。
如果刷新命令产生错误,如何在数据库中创建对象?
问题是由于实体类中的严重拼写错误造成的。
我通过使用 Symfony 的插件检查模式结构找到了它:
<?php
namespace Lp\LibBundle\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand;
class MyValidateSchemaCommand extends ValidateSchemaCommand
{
/**
* (non-PHPdoc)
* @see Tools/Console/Command/Doctrine\ORM\Tools\Console\Command.ValidateSchemaCommand::configure()
*
* Modifies name of the command to be in Doctrine namespace
* Adds the Helper em for the entity manager which is not defined in Doctrine class
* @author ulrich, 09/09/11
*/
protected function configure()
{
parent::configure();
$this->setName('doctrine:orm:validate-schema');
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
}
/**
* (non-PHPdoc)
* @see Tools/Console/Command/Doctrine\ORM\Tools\Console\Command.ValidateSchemaCommand::execute()
*
* Ajoute le Helper em pour l'entity manager qui n'est pas définis dans la class Doctrine
* @author ulrich, 09/09/11
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
return parent::execute($input, $output);
}
资料来源:乌尔里希 http://www.mon-code.net/article/26/ajouter-les-lignes-de-commande-doctrine2-a-symfony2
这允许使用此命令指令来检测实体拼写错误。
> php app/console doctrine:orm:validate-schema
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)