S
S
sgidlev2021-08-18 14:04:11
Doctrine ORM
sgidlev, 2021-08-18 14:04:11

How to properly extend from entity model in Doctrine?

Greetings.

Tell me how to properly extend from the entity model in Symfony?

I have a base model:

/**
 * @ORM\Entity(repositoryClass=DislocationRepository::class)
 */
class Dislocation
{
  /**
   * @ORM\Id()
   * @ORM\GeneratedValue()
   * @ORM\Column(type="integer")
   */
  protected $id;

  /**
   * @ORM\Column(type="integer")
   */
  protected $carNumber;


I need to inherit from this model in order to override current methods, such as displaying a date in a different format, etc.

/**
 * @Entity
 */
class DislocationDownloadingData extends Dislocation


I tried to add various options to the annotations, but it did not work.

/**
 * Abstract base class to be extended by my entity classes with same fields
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @ORM\Entity(repositoryClass=DislocationRepository::class)
 */
class Dislocation
{


And other combinations with @MappedSuperclass did not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
serginhold, 2021-08-19
@sgidlev

I need to inherit from this model in order to override current methods, such as displaying a date in a different format, etc.

the entity should not format dates in a different format, this is not yii or laravel for you, with monster models.
entities separately, logic separately, output separately.
because If you have any sign of an entity, what type it belongs to, then make a service that will determine how to work with an entity based on the type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question