Example #1
0
 /**
  * Saves the Relationship fields, relations, and category objects
  *
  * @param   Doctrine_Connection   $conn           The connection to use
  * @param   boolean               $saveCategory   Whether to save the category object; true by default
  * @return  Relationship                          The saved object
  */
 public function save(Doctrine_Connection $conn = null, $saveCategory = true)
 {
     if ($conn === null) {
         $conn = Doctrine_Manager::connection();
     }
     //make sure category is loaded
     $this->_loadCategory();
     try {
         $conn->beginTransaction();
         //if end_date is set, is_current must be false
         if ($this->end_date && $this->is_current) {
             $this->is_current = false;
         }
         $isModified = $this->isModified();
         //save Relationship
         $ret = parent::save($conn);
         //save category
         if ($saveCategory) {
             if ($object = $this->getCategoryObject()) {
                 $object->relationship_id = $this->id;
                 $object->save();
             }
         }
         //remove old category object
         if ($object = $this->_removedCategoryObject) {
             $object->delete();
             unset($this->_removedCategoryObject);
         }
         if ($isModified) {
             $this->updateEntitiesTimestamp();
         }
         $conn->commit();
     } catch (Exception $e) {
         $conn->rollback();
         throw $e;
     }
     $this->setIsSaving(false);
     return $ret;
 }