简体   繁体   English

原则2:不能使LifecycleCallBacks与单表继承实体一起使用?

[英]Doctrine 2: can't get LifecycleCallBacks to work with single table inheritance entities?

Is there a bug that doesn't allow this? 是否有不允许这样做的错误? I've put the LifecycleCallBacks annotation and a prepersist method into the base class (also tried the child classes as well) and can't get LifecycleCallBacks to work. 我已经将LifecycleCallBacks批注和一个prepersist方法放入基类(也尝试了子类),并且无法使LifecycleCallBacks正常工作。 Any input would be greatly appreciated! 任何投入将不胜感激! Thanks! 谢谢!

/**
 * @Entity(repositoryClass="Entity\Repository\EventRepository") 
 * @HasLifecycleCallbacks
 * @Table(name="events")
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="type", type="string")
 * @DiscriminatorMap({"phone" = "PhoneEvent", "meeting" = "MeetingEvent"})
 */
class Event implements \ActivityItem{

    /** @PrePersist */
    public function setComplianceStatus(){...}

}

This didn't work, so I also tried: 这没有用,所以我也尝试了:

/**
 * @Entity @HasLifecycleCallbacks
 */
class PhoneEvent extends Event{

    /** @PrePersist */
    public function setComplianceStatus(){}
}

I tried it with the mapping you proposed and there really seems to be a problem in that constellation. 我尝试过使用您建议的映射,但实际上该星座似乎存在问题。

It worked when I did: 当我这样做时,它起作用了:

/**
 * ...
 * @Entity
 * @HasLifecycleCallbacks
 */
class Event {
    ...

    /** @PrePersist */
    public abstract function setComplianceStatus();

    ...
}


/**
 * @Entity
 * @HasLifecycleCallbacks
 */
class PhoneEvent extends Event{

    /** @PrePersist */
    public function setComplianceStatus() {
        // implementation goes here
    }
}

As it seems the method has to be present in the parent class, even though it can be declared as abstract. 看起来该方法必须存在于父类中,即使可以将其声明为抽象方法。 Strange, might be a bug. 奇怪,可能是一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM