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. sql_flush.log
        6 kB
        James Bench
      2. msql.log
        2 kB
        Fabio B. Silva
      3. LocationData.php
        0.5 kB
        James Bench
      4. Location.php
        1 kB
        James Bench
      5. DDC2036Test.php
        4 kB
        Fabio B. Silva
      6. AbstractData.php
        1 kB
        James Bench

        Activity

        Hide
        Fabio B. Silva added a comment -

        Hi James,

        You must copy phpunit.xml.dist to phpunit.xml and change the database configurations.

        I have attached the mysql log, the test case works fine.

        Show
        Fabio B. Silva added a comment - Hi James, You must copy phpunit.xml.dist to phpunit.xml and change the database configurations. I have attached the mysql log, the test case works fine.
        Hide
        James Bench added a comment -

        It appears that it only attempts to delete 68 LocationData rows but in the database there are 76.

        Show
        James Bench added a comment - It appears that it only attempts to delete 68 LocationData rows but in the database there are 76.
        Hide
        James Bench added a comment -

        Okay, I've found the reason for this; the name isn't unique, some are duplicated.
        Once the duplicates are removed there are 68 rows.
        I'll add a unique index to the name column and hopefully this problem will go away.

        Not sure whether you would consider this a bug.

        Thanks for your help.

        Show
        James Bench added a comment - Okay, I've found the reason for this; the name isn't unique, some are duplicated. Once the duplicates are removed there are 68 rows. I'll add a unique index to the name column and hopefully this problem will go away. Not sure whether you would consider this a bug. Thanks for your help.
        Hide
        Fabio B. Silva added a comment -

        No problem, you are welcome

        Actually isn't a bug, it is a documented behavior.

        "Fields that are used for the index by feature HAVE to be unique in the database."

        http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/working-with-indexed-associations.html#working-with-indexed-assocations

        Show
        Fabio B. Silva added a comment - No problem, you are welcome Actually isn't a bug, it is a documented behavior. "Fields that are used for the index by feature HAVE to be unique in the database." http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/working-with-indexed-associations.html#working-with-indexed-assocations
        Hide
        Fabio B. Silva added a comment -
        Show
        Fabio B. Silva added a comment - Fields that are used for the index by feature HAVE to be unique in the database. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/working-with-indexed-associations.html#working-with-indexed-assocations

          People

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

            Dates

            • Created:
              Updated:
              Resolved: