Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.0.0BETA1
-
Component/s: Mapping Drivers
-
Labels:None
Description
Class-level annotations: @HasLifecycleCallbacks, @InheritanceType, @DiscriminatorField, @DiscriminatorMap have no effect when defined on @MappedSuperclass
You must explicitly set @HasLifecycleCallbacks for every document class to make callback work. As for inheritance annotations, you have to copy-paste all annotations to all document classes to make it work.
Simple example:
/** * @MappedSuperclass * @HasLifecycleCallbacks */ abstract class a { /** @String */ protected $a = ''; /** @PrePersist */ function prePersist() {$this->a = 'a';} } /** @Document(db="tests",collection="tests") */ class b extends a {} $b = new b(); $dm->persist($b); $dm->flush($b);
With this example prePersist won't be called. Not sure if it is bug or expected behavior, but it adds some inconvenience, especially with inheritance mapping.
This appears to work for me. I tested it here http://github.com/doctrine/mongodb-odm/commit/af9aa0f674f8b542c89f8c975ac403fd46f6e29e