0

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") 
 * @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(){}
}
Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
blacktie24
  • 4,985
  • 6
  • 41
  • 52
  • 2
    It would greatly help if you posted your entities. – kgilden Sep 08 '11 at 07:33
  • @gilden, thx for the advice, added a code sample. – blacktie24 Sep 08 '11 at 17:45
  • Just going through the basic things first: Are you using 'AcmeDemoBundle:Event' instead of `AcmeDemoBundle:ActivityItem` for fetching the entities? Did you make absolutely sure they're not called (e.g called `die()` immediately in your event handlers)? Are the entities getting persisted? You could also try prepending `@ORM\` in front of any annotations related to Doctrine (probably doesn't make a difference, but I'm using them, because they were required in earlier versions). – kgilden Sep 08 '11 at 17:59
  • I think you have the same problem as this guy: http://stackoverflow.com/questions/7320425/doctrine-2-lifecyclecallbacks-with-abstract-base-class-are-not-called/7345412#7345412 it looks like it's not supported yet. – Kees Schepers Sep 12 '11 at 19:51

1 Answers1

3

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.

Max
  • 15,693
  • 14
  • 81
  • 131