DoctrineExtensions Notice: undefined index: foreignKey in $em->getRepository('Gedmo\\Trans



我试图像本例中那样保存多个翻译,但出现了一个错误。

这是实体

/**
* @ORMEntity
* @GedmoTranslationEntity(class="BaseTranslation")
* @ORMTable(name="c_Base")
*/
class Base {
/**
* @ORMColumn(type="bigint")
* @ORMId
*/
private $id;
/**
* Hexaid
* @var string
*/
private $hid;
/**
* @ORMColumn(type="string")
* @GRIDColumn(title="name")
* @GedmoTranslatable
* @var string
*/
private $name;
/**
* @ORMColumn(type="text", nullable=true)
* @GedmoTranslatable
* @var string
*/
private $description;
/**
* GRIDColumn(title="translations",field="translations.content")
* @ORMOneToMany(
*     targetEntity="BaseTranslation",
*  mappedBy="object",
*  cascade={"persist", "remove"}
* )
* @AssertValid(deep = true)
*/
private $translations;

翻译实体

/**
* EntityTranslationProductTranslation.php
* @ORMEntity
* @ORMTable(name="c_base_translations",
*   uniqueConstraints={@ORMUniqueConstraint(name="lookup_unique_idx", columns={
*     "locale", "object_id", "field"
*   })}
* )
*/
class BaseTranslation extends AbstractPersonalTranslation{
/**
* @ORMManyToOne(targetEntity="Base", inversedBy="translations")
* @ORMJoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $object;
public function __construct($locale, $field, $value)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($value);
}
}

我尝试使用多种翻译

$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('Gedmo\Translatable\Entity\Translation');
$article = new Base();
$article->setName('content en');
$repository->translate($article, 'name', 'de', 'name de')
->translate($article, 'name', 'pl', 'name pl')
;
$em->persist($article);
$em->flush();

并获得

注意:未定义的索引:foreignKey

[1] SymfonyComponentDebugExceptionContextErrorException: Notice: Undefined index: foreignKey
at n/a
in /home/grek/PhpstormProjects/welasy/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 655
at SymfonyComponentDebugErrorHandler->handleError('8', 'Undefined index: foreignKey', '/home/grek/PhpstormProjects/welasy/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php', '655', array('name' => 'foreignKey'))
in /home/grek/PhpstormProjects/welasy/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 655
at DoctrineORMMappingClassMetadataInfo->getReflectionProperty('foreignKey')
in /home/grek/PhpstormProjects/welasy/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php line 80
at GedmoTranslatableEntityRepositoryTranslationRepository->translate(object(Base), 'name', 'de', 'name de')
in /home/grek/PhpstormProjects/welasy/vendor/Mea/CharterBundle/Controller/ResourcesController.php line 171
at MeaCharterBundleControllerResourcesController->oneViewByHidAction('9888fff563a6a42', '2015;20')
in  line 
at call_user_func_array(array(object(ResourcesController), 'oneViewByHidAction'), array('9888fff563a6a42', '2015;20'))
in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 3028
at SymfonyComponentHttpKernelHttpKernel->handleRaw(object(Request), '1')
in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 2990
at SymfonyComponentHttpKernelHttpKernel->handle(object(Request), '1', true)
in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 3139
at SymfonyComponentHttpKernelDependencyInjectionContainerAwareHttpKernel->handle(object(Request), '1', true)
in /home/grek/PhpstormProjects/welasy/app/bootstrap.php.cache line 2383
at SymfonyComponentHttpKernelKernel->handle(object(Request))
in /home/grek/PhpstormProjects/welasy/web/app_dev.php line 28

将"@ORM\GeneratedValue"添加到基本

/**
* @ORMColumn(type="integer")
* @ORMId
* @ORMGeneratedValue
*/
private $id;

相关内容

  • 没有找到相关文章

最新更新