Translation Behaviour is looking for \Enti folder

2019-09-01 14:37发布

I am trying to translate the slug of a BlogPost in multiple languages. I decided to use KnpLabs/DoctrineBehaviors to help me with the task. I installed the bundle, got the sluggable behaviour to work in minutes. However, when I add the translatable behaviour, I get can't update my schema.

I get the following error when I try to update my database schema (I know that the --force is not on the picture, but it does the same result).

enter image description here

Here's my BlogPost Entity :

namespace MyProject\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * @ORM\Entity
 */
class BlogPost
{  
    use ORMBehaviors\Sluggable\Sluggable,
        ORMBehaviors\Translatable\Translation;


    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }


    public function getSluggableFields()
    {
        return [ 'title' ];
    }

}

And here's my BlogPostTranslation entity :

namespace MyProject\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use ORMBehaviors\Translatable\Translation;

/**
 * @ORM\Entity
 */
class BlogPostTranslation
{
    use ORMBehaviors\Translatable\Translation;


    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $name;


    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    public function setTitle($title)
    {
        $this->title = $title;
    }

    public function getTitle()
    {
        return $this->title;
    }
}

I did some debugging with doctrine and the "TargetEntity" is really looking for a folder "Enti". This only occur if I add the translatable behaviour. If I remove it, I can update and use the sluggable behaviour without any problem.

1条回答
beautiful°
2楼-- · 2019-09-01 14:49

You problem lies within the BlogPost entity. You have to use the Translatable trait instead of the Translation trait.
To fix your issue change the use statement to:

/**
 * @ORM\Entity
 */
class BlogPost
{  
    use ORMBehaviors\Sluggable\Sluggable,
        ORMBehaviors\Translatable\Translatable;
    // ...

Also check out the section about proxy translations.

查看更多
登录 后发表回答