Symfony2 MappedSuperClass 和教义:generate:entities [英] Symfony2 MappedSuperClass and doctrine:generate:entities
问题描述
我有一个Offer"类(MapperSuperclass)和另外 2 个扩展它的类,PrivateOffer"和PublicOffer".
I have a "Offer" class (MapperSuperclass) and 2 more classes extending it, "PrivateOffer" and "PublicOffer".
我遇到的问题是,当我运行doctrine:generate:entities"命令时,PrivateOffer"和PublicOffer"两个类都充满了与 MappedSuperclassOffer"类相同的属性,而且它也是 getter 和 setter方法.
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.
如果我删除它们并只在Offer"类中使用它们,doctrine:schema:update"会按预期工作,但我需要再次运行doctrine:generate:entities",所以每次都会破坏我的扩展课程.
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.
如果doctrine:generate:entities"扩展了 MappedSupper 类,为什么会复制两个类中的所有属性和 setter/getter 方法?
Why is the "doctrine:generate:entities" duplicating all the properties and setter/getter methods in both of the classes, if they extends the MappedSupperclass?
谢谢大家:)
优惠等级:
namespace ProJobBundleEntity;
use DoctrineORMMapping as ORM;
/**
* Offer
*
* @ORMMappedSuperclass()
*/
class Offer
{
/**
* @var string
*
* @ORMColumn(name="name", type="string", length=255)
*/
protected $name;
....more properties...
}
PrivateOfferClass:
PrivateOfferClass:
<?php
namespace ProJobBundleEntity;
use DoctrineORMMapping as ORM;
/**
* PrivateOffer
*
* @ORMTable(name="private_offer")
* @ORMEntity
*/
class PrivateOffer extends Offer
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
PublicOfferClass:
PublicOfferClass:
<?php
namespace ProJobBundleEntity;
use DoctrineORMMapping as ORM;
/**
* PublicOffer
*
* @ORMTable(name="public_offer")
* @ORMEntity
*/
class PublicOffer extends Offer
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
推荐答案
这是 Doctrine 中的一个已知行为(不是说:bug):在您的场景中,所有实体属性都必须是私有的.只能通过 getter 访问它们.
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.
这篇关于Symfony2 MappedSuperClass 和教义:generate:entities的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!