DoctrineBehaviors icon indicating copy to clipboard operation
DoctrineBehaviors copied to clipboard

Using InheritanceType

Open Ciloe opened this issue 2 years ago • 2 comments

Hi there,

I have a discrimator inheritance :

/**
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({"activity" = "Activity", "meals" = "Meal", "bookable_table" = "BookableTable"})
 */
abstract class AbstractBookableActivity extends AbstractEntity implements TranslatableInterface
{
    use TranslatableTrait;
}

With an entity that extends the abstract entity

/**
 * @ORM\Entity(repositoryClass="App\Repository\ActivityRepository")
 */
class Activity extends AbstractBookableActivity
{
}

Now I will create the translation object

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait;
use Symfony\Component\Serializer\Annotation as Serializer;

/**
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({"activity" = "ActivityTranslation", "meals" = "MealTranslation", "bookable_table" = "BookableTableTranslation"})
 */
abstract class AbstractBookableActivityTranslation extends AbstractEntity implements TranslationInterface
{
    use TranslationTrait;

    /**
     * @ORM\Column(type="string")
     */
    #[Serializer\Groups(['trace_change'])]
    public string $name = '';

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    #[Serializer\Groups(['trace_change'])]
    public ?string $description = null;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    #[Serializer\Groups(['trace_change'])]
    public ?string $smallDescription = null;
}

And activity translation :

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class ActivityTranslation extends AbstractBookableActivityTranslation
{
}

But it's not working too, in insert, discr is always null. image

How can we do to correct this issue ?

Ciloe avatar Jun 10 '22 10:06 Ciloe

I followed this commit https://github.com/KnpLabs/DoctrineBehaviors/pull/688/files

Ciloe avatar Jun 27 '22 09:06 Ciloe

I posted an issue on doctrine. Can you check this ?

Ciloe avatar Jun 27 '22 09:06 Ciloe