2

I have been struggling with defining cascade behavior in Doctrine ORM.

According to the documentation, one is supposed to use onDelete: CASCADE for database-level cascade (which is what I am trying to achieve here).

A complete example may be seen on the Symfony tutorial.

However, all such cascade specifications are ignored in my schema.

Here is the relevant excerpt:

Advancement:
  columns:
    association_id:
      type: integer(4)
      notnull: true
    task_id:
      type: integer(4)
      notnull: true
    state:
      type: enum
      values: ['todo', 'current', 'done', 'cancelled']
      notnull: true
  relations:
    Association:
      class: Association
      local: association_id
      foreignType: one
      onDelete: CASCADE
    Task:
      class: Task
      local: task_id
      foreignType: one
      onDelete: CASCADE

Of course, the Task and Association tables are defined correctly. I won't post them here in the first place to avoid a too long question, but please ask if that seems necessary.

Here is the generated SQL (linebreaks mine):

CREATE TABLE advancement
(id INTEGER PRIMARY KEY AUTOINCREMENT,
association_id INTEGER NOT NULL,
task_id INTEGER NOT NULL,
state VARCHAR(255) NOT NULL);

Not a trace of a CASCADE (nor a REFERENCES, by the way…). Of course, cascading does not work, and I had to implement it manually by altering the default backend actions.

Does anyone know what I am doing wrong here?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MattiSG
  • 3,796
  • 1
  • 21
  • 32
  • Doctrine generates the foreign key relations at the end of the generated sql (data/sql/schema.sql), check if they are there. – Maerlyn Sep 23 '11 at 20:47
  • Nope, I have actually `grep`ped through all generated SQL, and no trace of `CASCADE`… Thanks for the precision though! – MattiSG Sep 27 '11 at 09:09

1 Answers1

1

I think doctrine will shut up about the fact that your RDBMS (is it MySQL?) does not support cascades if it doesn't. This is the case if you use MySQL with the MyISAM storage engine (which does not support REFERENCES either, by the way...). If I were you, I'd try to create a cascade directly with your RDBMS client, just to check whether it is possible or not.

greg0ire
  • 22,714
  • 16
  • 72
  • 101