Symfony2 MappedSuperClass and Doctrine: Generate: Entities

I have a class "Offer" (MapperSuperclass) and two more classes that extend it: "PrivateOffer" and "PublicOffer".

The problem is that when I run the doctrine: generate: entities command, both the PrivateOffer and PublicOffer classes are populated with the same properties as the MappedSuperclass Offer class, as well as its getter and setter methods.

If I delete them and live them only in the class "Suggestion", "doctrine: schema: update" works well, as expected, but I need to run "doctrine: generate: entities" again so that it will crash every time my extended classes.

Why does doctrine: generate: entities duplicate all setter / getter properties and methods in both classes if they extend the MappedSupperclass?

Thanks everyone :)

OfferClass:

namespace Pro\JobBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Offer * * @ORM\MappedSuperclass() */ class Offer { /** * @var string * * @ORM\Column(name="name", type="string", length=255) */ protected $name; ....more properties... } 

PrivateOfferClass:

 <?php namespace Pro\JobBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * PrivateOffer * * @ORM\Table(name="private_offer") * @ORM\Entity */ class PrivateOffer extends Offer { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * Get id * * @return integer */ public function getId() { return $this->id; } } 

PublicOfferClass:

 <?php namespace Pro\JobBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * PublicOffer * * @ORM\Table(name="public_offer") * @ORM\Entity */ class PublicOffer extends Offer { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * Get id * * @return integer */ public function getId() { return $this->id; } } 
+5
source share
1 answer

This is a known behavior (not to say: error) in Doctrine: in your script, all properties of the entity must be private. Access to them is possible only through getters.

+10
source

Source: https://habr.com/ru/post/1202169/


All Articles