/** * @internal * * @return void */ protected function deleteManagedObject(MManagedObject $object) { $object->discardChanges(); // Remove all object's relationships foreach ($object->entity()->relationships() as $relationship) { $relationshipObjects = $object->objectForAttribute($relationship); if ($relationshipObjects) { foreach ($relationshipObjects->toArray() as $relationshipObject) { $object->removeObjectFromRelationship($relationship, $relationshipObject); } } } $this->saveManagedObject($object); // Remove object from the database $query = Sf("DELETE FROM `%s` WHERE `objectID` = ?", $object->entity()->plural()); $statement = $this->connection()->prepare($query->stringValue()); if (!$statement->execute(array($object->objectID()))) { throw new MPersistentStoreException(Sf("Could not delete entity [%s]", $object->entity()->name())); } }