问题
I have a "Offer" class (MapperSuperclass) and 2 more classes extending it, "PrivateOffer" and "PublicOffer".
The problem I have is, when I run "doctrine:generate:entities" command, both classes "PrivateOffer" and "PublicOffer" are fullfilled with the same properties than the MappedSuperclass "Offer" class, and also it's getter and setter methods.
If I remove them and live them only in the "Offer" class, the "doctrine:schema:update" works well as expected, but I need to run the "doctrine:generate:entities" again so, it ruins everytime my extended classes.
Why is the "doctrine:generate:entities" duplicating all the properties and setter/getter methods in both of the classes, if they extends the MappedSupperclass?
Thank you all :)
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;
}
}
回答1:
This is a known behaviour (not to say: bug) in Doctrine: In your scenario, all entity properties must be private. Accessing them must only be possible via the getters.
来源:https://stackoverflow.com/questions/25749418/symfony2-mappedsuperclass-and-doctrinegenerateentities