Syfmony Embedded classes for entity - fieldMappings inheritance

155 views Asked by At

I've got the following issue and i can't found on the entire internet what should be the solution..

I've created a class named IdColumn and i want this class to be used in every entity of my project due to standardise reasons.

#[ORM\Embeddable]
class IdColumn
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(name: "id", type: "integer", options:["unsigned" => true])]
    protected int $id;

    public function getId(): ?int
    {
        return $this->id;
    }
}

After that i've created my entity like following and used the IdColumn

#[ORM\Entity(repositoryClass: MyClassRepository::class)]
class MyClass
{
    #[ORM\Embedded(class: IdColumn::class, columnPrefix: false)]
    protected int $id;

The problem is that SF and Doctrine returns the fieldMappings of this entity for column $id as 'id.id' . So every time if i want to do a query, or insert something i've got to use that 'id.id' statement.

The question: Is possible to overwrite the fieldMappings in symfony ? Or to use the last class property? I've got this issue also with another properties that are make from 3 classes and returns a fieldMappings like 'myFirstClassProperty.mySecondClassProperty.myFinalClassProperty'.

I've looked into Doctrine documentation and Symfony but no one ever discussed about fieldMappings issue with embeddable.

In the first place, also the column name was like id_id but the column_prefix: false resolved this issue.

Thank you :).

Note: Using Symfony 6.2 and Doctrine 2.13

0

There are 0 answers