I've come across this scenario a few times in working on a current project. I have to see if a record exists then if it doesn't I need to add it, if it does then I need to update. What is the standard way of doing this with Doctrine?
I seem to be querying to see if the record exists using a find* method. Then if that returns a positive result (object), I use that object to update. Otherwise, (no record found) I have to create another object and save().
For some reason this just seems inefficient. Is there a better way or am I just being weird? :)
$user = Doctrine_Core::getTable('Model_User')->findOneByEmail('[email protected]');
if (!$user) {
$user = new Model_User();
$user->fromArray($values); // $values comes from form or wherever
$user->save();
} else {
$user->fromArray($values);
$user->save();
}