DDC-2036: indexBy breaks cascade remove #2566

Open
opened 2026-01-22 13:57:08 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 20, 2012).

Jira issue originally created by user jebbench:

Adding the annotation indexBy causes the cascade annotation to be ignored:

/****
*

  • @var ArrayCollection
  • @ORM\OneToMany(targetEntity="LocationData", mappedBy="location", indexBy="name", cascade={"persist", "remove"})
    */
    protected $data;

Will cause an error when deleting the objects:

An exception occurred while executing 'DELETE FROM location WHERE id = ?' with params {"1":19306}:

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (symfony.location*data, CONSTRAINT FK_2DF7462364D218E FOREIGN KEY (location*id) REFERENCES location (id))

Removing indexBy fixes the issue.

My class structure is:

Location has many LocationData
LocationData extends AbstractData

The name field I am trying to index by comes from the AbstractData class.

Originally created by @doctrinebot on GitHub (Sep 20, 2012). Jira issue originally created by user jebbench: Adding the annotation indexBy causes the cascade annotation to be ignored: /**** * - @var ArrayCollection - - @ORM\OneToMany(targetEntity="LocationData", mappedBy="location", indexBy="name", cascade={"persist", "remove"}) */ protected $data; Will cause an error when deleting the objects: An exception occurred while executing 'DELETE FROM location WHERE id = ?' with params {"1":19306}: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`symfony`.`location*data`, CONSTRAINT `FK_2DF7462364D218E` FOREIGN KEY (`location*id`) REFERENCES `location` (`id`)) Removing indexBy fixes the issue. My class structure is: Location has many LocationData LocationData extends AbstractData The name field I am trying to index by comes from the AbstractData class.
admin added the Bug label 2026-01-22 13:57:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2566