symfony - 找不到关联目标类
问题描述
我正在使用 Symfony 3.4 和 knp 学说行为进行翻译。
我的实体文章看起来像:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* Article
*
* @ORM\Table(name="article")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ArticleRepository")
*/
class Article
{
use ORMBehaviors\Translatable\Translatable;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
//...
}
然后我有实体 ArticleTranslation
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* @ORM\Entity
*/
class ArticleTranslation
{
use ORMBehaviors\Translatable\Translation;
/**
* @ORM\Column(type="string", length=128)
*/
protected $headline;
//...
}
现在我的应用程序给我一个错误:
Unable to find the association target class of "headline" in AppBundle\Entity\Article.
Article
它期望和之间的关系ArticleTranslation
。文档中有一句话:
默认命名约定(或通过 trait 方法自定义)避免您手动处理实体关联。它由 TranslationSubscriber 自动处理。
为什么会这样?我错过了什么?
编辑
bin/控制台原则:架构:更新
[OK] Nothing to update - your database is already in sync with the current entity metadata.
bin/控制台调试:配置 knp_doctrine_behaviors
knp_doctrine_behaviors:
translatable: true
blameable: false
geocodable: false
loggable: false
sluggable: false
soft_deletable: false
sortable: false
timestampable: false
tree: false
我在奏鸣曲管理中使用它,可翻译 a2lix。
文章Admin.php:
<?php
namespace AppBundle\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
final class ArticleAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('headline', TranslationsType::class);
}
//...
}
解决方案
推荐阅读
- apache-spark - 如何在写入数据时使用“Salt”进行火花重新分区
- python - 如何将xml xpath解析为list python
- javafx - 如何将 javaFx 中的按钮链接到 rpi 上的 gpio 引脚
- c# - 如何使用 oData 查询从 azure graph API 过滤结果
- angular - img标签内的Angular ngStyle没有动态更新
- google-sheets - 在 Excel 或 Google 表格中删除重复项时求和值和平均值
- apple-push-notifications - iOS 13 杀死应用程序,因为它在收到 PushKit VoIP 回调后从未向系统发布来电
- python - Pymysql 重复键更新
- sql - 如果表 2 中存在数据(id)但如果表 2 为空,如何从表 1 中删除数据,则删除表 1 中的所有数据?
- flutter - Flutter 中的 pub 代表什么