Symfony2: PrePersist/PreUpdate lifecycle-event not fired

后端 未结 1 962
花落未央
花落未央 2021-02-09 17:36

Two Entities GalleryAlbum and GalleryImage have OneToMany/ManyToOne relationship:

One GalleryAlbum ==== can have ====> Many Ga

相关标签:
1条回答
  • 2021-02-09 18:33

    The first time you call persist doctrine will only save $album and not its images. You must specify that you want doctrine to cascade the persist by specifying it in the $images declaration:

        /**
         * @ORM\OneToMany(targetEntity="GalleryImage", mappedBy="parent", cascade={"persist", "remove"})
         */
        protected $images;
    

    This way when you call persist($album) it will also persist your images and should trigger preUpload in your GalleryImage. There are a few different options available for cascading and they are explained well here:

    Doctrine transitive persistence cascade operations

    0 讨论(0)
提交回复
热议问题