How to make the method annotated with @PrePersist run before a property is set by @Timestampable?

Viewed 142

I have an Entity

class Foo{
    /**
     * @var \DateTime
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetimetz")
     */
    private $createdAt;

    /**
     * @ORM\PrePersist
     */
    public function bar()
    {
        $this->createdAt->getTimestamp();
    }
}

Unfortunately, the Foo::bar() is run before the TimestampableListener has the opportunity to set the proper value of $this->createdAt.

I was trying tu change the priority of the event listener in services.yml (as hinted in Can I define the order in which event listeners / subscribers are called in doctrine?), but it does not work.

1 Answers
Related