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. Any input would be greatly appreciated! Thanks!
/**
* @Entity(repositoryClass="Entity\Repository\EventRepository"开发者_JAVA百科)
* @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.
精彩评论