Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3134

Inconsistent defaults for onDelete when defining many-to-many relations

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony 2.5.0-BETA2

      Description

      When defining a relation with the following annotation:

      /**
       * @ORM\ManyToMany(targetEntity="A\B\C")
       */
      

      The following SQL is generated for the foreign key constraints:

      ALTER TABLE the_table ADD CONSTRAINT FK_A63A409AA76ED395 FOREIGN KEY (something1) REFERENCES thing2 (id) ON DELETE CASCADE;
      ALTER TABLE the_table ADD CONSTRAINT FK_A63A409AF8BD700D FOREIGN KEY (something2) REFERENCES thing1 (id) ON DELETE CASCADE;
      

      As it can be seen, the default seems to be to include ON DELETE CASCADE. This feels like a dangerous behaviour (and I couldn't find it documented), but fair enough. The inconsistency comes when adding:

      /**
       * @ORM\ManyToMany(targetEntity="A\B\C")
       * @ORM\JoinTable(name="the_table",
       *      joinColumns={@ORM\JoinColumn()},
       *      inverseJoinColumns={@ORM\JoinColumn()}
       * )
       */
      

      In this case, even if we are not providing any values for the join and inverse join columns, we get:

      ALTER TABLE the_table ADD CONSTRAINT FK_A63A409AA76ED395 FOREIGN KEY (something1) REFERENCES something2 (id);
      ALTER TABLE user_unit ADD CONSTRAINT FK_A63A409AF8BD700D FOREIGN KEY (something2) REFERENCES something1 (id);
      

      As it can be seen, the ON DELETE CASCADE is gone.

      I understand this is the case because, when giving empty JoinColumn annotations it's not the engine defaults that are processed, but the inferred values for the annotation. Still, this seems to be either a bug or an undocumented behaviour.

      Am I doing anything wrong here? Should this be looked into?

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Adria Lopez
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: