As for Doctrine, for embedded fields to specify the field name in the database table?

Happy new year to all! :)

There is an entity Client, which contains different information about the client. I begs the question how with Doctrine in database to assign names to the fields "surname", "name" and "patronymic" with the approach that I have used.

In essence, the Client has a field name, it is represented as a value object ω with the name FullName. For this object, the doctrine is used for embedded connection, spelled out in the annotations.

FullName in turn contains three fields: surname, name and patronymic. In this case, each field presents its own value object ω, which is simply called Name. Why? Name is able to shorten the name, it was made into a separate value object. For example, "Ivan" will reduce to "I.". Later in the FullName can be easily done method that returns the abbreviated name of the user "Ivanov I. I.".

To make it clear what was going on, I have some code like this:

/** @ORM\Entity() */
class Client
{
 /** @ORM\Id() */
 private int $id;
 /** @ORM\Embedded(class="FullName") */
 private FullName $name;

 public function __construct(FullName $name)
{
 $this->name = $name;
}
}

/** @ORM\Embeddable() */
class FullName 
{
 /** @ORM\Embedded(class="Name") */
 private Name $surname;
 /** @ORM\Embedded(class="Name") */
 Name private $name;
 /** @ORM\Embedded(class="Name") */
 private Name, $patronymic;

 public function __construct(Name $surname, Name $name, Name, $patronymic)
{
 $this->surname = $surname;
 $this->name = $name;
 $this->patronymic = $patronymic;
}

 public function getFullName()
{
 return implode(' ', [
$this->surname->getFull(),
$this->name->getFull(),
$this->patronymic->getFull(),
]);
}

 public function getShortName()
{
 return implode(' ', [
$this->surname->getFull(),
$this->name->getShort(),
$this->patronymic->getShort(),
]);
}
}

/** @ORM\Embeddable() */
class Name
{
 /** @ORM\Column(type="string", length=100) */
 private string $value;

 public function __construct(string $value)
{
 $this->value = $value;
}

 public function getFull(): string
{
 return $this->value;
}

 public function getShort(): string
{
 $value = $this->value;
 if ($value) {
 $value = mb_substr($value, 0, 1) . '.';
}

 return $value;
}
}


As the surname, name and patronymic are stored in their object class Name in a field with the same name value, we have to rely on automatically added columnPrefix, such as "surname_", so in the database table field work "surname_value", "name_value", "patroymic_value". Such a naming I don't like is purely aesthetic. I would like to get rid of the suffix "_value" in their naming. But how can I explain this Doctrine? Is that even possible?
April 4th 20 at 00:46
1 answer
April 4th 20 at 00:48
Solution
not. Override names for Embedded is not supported
https://stackoverflow.com/questions/53497770/doctr...
Sorry. Until then put up with the suffix "_value". - marcel.Schumm commented on April 4th 20 at 00:51

Find more questions by tags SymfonyDoctrine ORM