symfony 1.4 chaining preDelete events for related tables
Is there a way to chain the preDelete() events in Symfony 1.4?
I have two tables: one master and one slave. In schema.yml I have defined them so that the slave records CASCADE the Deletion when a master record gets deleted.
But also, the slave deletion process needs to run some preprocessing which I'm intending to code in the preDelete event method of the slave record definition.
If I delete the slave record alone, I can get to this preDelete() event but if I delete the slave record through the master record, I only access to the preDelete() event in the master record definition. Can I access the preDelete event in the slave by the way of the master one?
Relevant code follows:
schema.yml
Master开发者_StackOverflow社区:
relations:
Slave:
Slave:
relations:
Master:
onDelete: CASCADE
lib/model/doctrine/Master.class.php
class Master extends BaseMaster
{
public function preDelete($event)
{
//master predelete processing...
}
}
lib/model/doctrine/Slave.class.php
class Slave extends BaseSlave
{
public funcion preDelete($event)
{
//slave predelete processing...
}
}
This wouldn't work, because "onDelete: CASCADE" is a database event, hence there's no way of hooking it to your code. To to able to do that, you need to use application cascade delete, which is less efficient though.
Slave:
columns:
master_id: integer
Master:
columns: ~
relations:
Slave:
local: id
foreign: master_id
type: many
foreignType: one
cascade: [delete]
Notice also that you will have to define the relation on the opposite side in this case.
精彩评论