tags:

views:

44

answers:

2

I am using Doctrine 1.2 in my project. The schema.yml file contains:

Campaign:
  tableName: campaign
  actAs:
    Timestampable:
      created:
        name: created_datetime
        type: timestamp
        format: Y-m-d H:i:s
      updated:
        disabled: true
  columns:
    id:
      type: integer(9)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
   ...
  relations:
    CampaignImages:
      local: id
      foreign: campaign_id
      type: many
      cascade: [delete]
   ...
CampaignImages:
  tableName: campaign_images
  columns:
    id:
      type: integer(9)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    campaign_id:
      type: integer(9)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    ...

I have defined CampaignImages::delete() method and put some debugging code there, but it does not get executed when Campaign::delete() is called.

Isn't cascade:[delete] meant precisly for this reason? I don't want to use database level cascades, because image files associated with CampaignImage must be deleted when deleting record.

+2  A: 

Cascade delete doesn't run delete() method. However, it guarantees that hooks are run.

If you need to implement any pre/post delete logic you shouldn't overwrite delete() method but rather use preDelete() or postDelete() hooks.

kuba
Thanks kuba, I was looking for just that.
fest
A: 

Aren't you looking for

 onDelete: CASCADE

It sounds more like the option you want.

http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/en#relationships:foreign-key-constraints:integrity-actions

DrColossos
"onDelete: CASCADE" is for database level cascades. It completely bypasses doctrine.
kuba