views:

83

answers:

1

I have a listener which contains a preSave() method. Is there a way for me to halt doctrine from calling the save method if a condition fails. Unfortunately I am not allowed to throw an exception. Is there any other way?

+2  A: 

My first idea would be to set a flag in the preSave()-method and to check for that flag in the save()-method. But I think skipOperation() is what you are looking for:

public function preSave(Doctrine_Event $event)
{
    if (!$condition) {
        $event->skipOperation();
    }
}
Thomas Schuster
Wow that is awesome! I never knew about skipOperation! Awesome!
balupton
i will try the skipOperation.......but I am not sure about the flag approach since the preSave() is called after the save() method of our model but before the Doctrine_Record'd save() method
rahul