Reputation: 1635
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.
Upvotes: 0
Views: 1059
Reputation: 1538
I have solved in another way
in Campaign class you put this
public function setUp() {
parent::setUp();
// to delete cascaded items
$CampaignRel = $this->_table->getRelation("CampaignImages");
$CampaignRel->offsetSet('cascade', array('delete'));
}
it did work for me that way
Upvotes: 1
Reputation: 12988
Aren't you looking for
onDelete: CASCADE
It sounds more like the option you want.
Upvotes: -2
Reputation: 36191
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.
Upvotes: 3