One to Many keep deleting my parent entity even when I'm only editing it #5557

Closed
opened 2026-01-22 15:11:12 +01:00 by admin · 2 comments
Owner

Originally created by @AntonSmatanik on GitHub (May 24, 2017).

Originally assigned to: @Ocramius on GitHub.

I have parent and child entity. Whenever I edit data even if I have done no changes parent entity is deleted. That's crazy behavior. Here is my code for parent:

/**
     * @OneToMany(targetEntity="Gallery", mappedBy="promotion", cascade={"persist", "remove"})
     */
    private $galleries;

public function __construct() {
        $this->galleries = new ArrayCollection();
    }
    
    public function getGalleries() {
        return $this->galleries;
    }
    
    public function addGallery($gallery)
    {
        $gallery->setPromotion($this);
        $this->galleries[] = $gallery;

        return $this;
    }

    public function removeGallery($gallery)
    {
        $gallery->setPromotion(null);
        $this->galleries->removeElement($gallery);
    }

And here for child:

/**
     * @ManyToOne(targetEntity="Promotion", inversedBy="galleries")
     */
    
    private $promotion;

I don't know what to do, I have already spend hours on this...

Originally created by @AntonSmatanik on GitHub (May 24, 2017). Originally assigned to: @Ocramius on GitHub. I have parent and child entity. Whenever I edit data even if I have done no changes parent entity is deleted. That's crazy behavior. Here is my code for parent: ``` /** * @OneToMany(targetEntity="Gallery", mappedBy="promotion", cascade={"persist", "remove"}) */ private $galleries; public function __construct() { $this->galleries = new ArrayCollection(); } public function getGalleries() { return $this->galleries; } public function addGallery($gallery) { $gallery->setPromotion($this); $this->galleries[] = $gallery; return $this; } public function removeGallery($gallery) { $gallery->setPromotion(null); $this->galleries->removeElement($gallery); } ``` And here for child: ``` /** * @ManyToOne(targetEntity="Promotion", inversedBy="galleries") */ private $promotion; ``` I don't know what to do, I have already spend hours on this...
admin added the Invalid label 2026-01-22 15:11:12 +01:00
admin closed this issue 2026-01-22 15:11:12 +01:00
Author
Owner

@lcobucci commented on GitHub (May 24, 2017):

@AntonSmatanik that looks weird but is a bit hard for us to do something with just that info, could you please try to reproduce it using a functional test and sends a PR? You can find examples in 2a239be45e/tests/Doctrine/Tests/ORM/Functional/Ticket

@lcobucci commented on GitHub (May 24, 2017): @AntonSmatanik that looks weird but is a bit hard for us to do something with just that info, could you please try to reproduce it using a functional test and sends a PR? You can find examples in https://github.com/doctrine/doctrine2/tree/2a239be45ec4e64c736e4277cde8bff376ef2402/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@AntonSmatanik commented on GitHub (May 29, 2017):

Ok, I think there is a problem in easy admin bundle.

@AntonSmatanik commented on GitHub (May 29, 2017): Ok, I think there is a problem in easy admin bundle.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5557