Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Can't Fix
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
      None
    • Environment:
      Ubuntu 12.04, PHP 5.3, 64 Bit, Symfony 2

      Description

      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.

      1. AbstractData.php
        1 kB
        James Bench
      2. DDC2036Test.php
        4 kB
        Fabio B. Silva
      3. Location.php
        1 kB
        James Bench
      4. LocationData.php
        0.5 kB
        James Bench
      5. msql.log
        2 kB
        Fabio B. Silva
      6. sql_flush.log
        6 kB
        James Bench

        Activity

        James Bench created issue -
        James Bench made changes -
        Field Original Value New Value
        Description 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.
        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.
        James Bench made changes -
        Description 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.
        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.
        James Bench made changes -
        Attachment AbstractData.php [ 11329 ]
        Attachment Location.php [ 11330 ]
        Attachment LocationData.php [ 11331 ]
        Fabio B. Silva made changes -
        Attachment DDC2036Test.php [ 11332 ]
        Fabio B. Silva made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        James Bench made changes -
        Attachment sql_flush.log [ 11333 ]
        Fabio B. Silva made changes -
        Attachment msql.log [ 11334 ]
        Fabio B. Silva made changes -
        Assignee Benjamin Eberlei [ beberlei ] Fabio B. Silva [ fabio.bat.silva ]
        Fabio B. Silva made changes -
        Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
        Fabio B. Silva made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Can't Fix [ 7 ]

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            James Bench
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: