首页 > 解决方案 > 找不到关联目标类

问题描述

我正在使用 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);
    }

    //...
}

标签: symfonydoctrine-ormsonata-admina2lix-translation

解决方案


推荐阅读