/**
  * Disconnects the relation between 2 objects.
  * Runs relation analyzer if needed.
  * @uses analyzeRelations
  * @param object $object the class to disconnect.
  */
 public function Disconnect($object, $id = false)
 {
     if (!$object && !$id) {
         return;
     }
     if (!$object instanceof dbObject && $id != false) {
         $object = new $object(false);
         $object->databaseInfo->ID = $id;
         // a tweak to disconnect an uninitialized object so that it doesn't have to fetch the whole row first.
     }
     $className = get_class($object);
     if (array_key_exists($className, $this->relations)) {
         switch ($this->relations[$className]->relationType) {
             case RELATION_SINGLE:
                 $this->changedValues[$object->databaseInfo->primary] = '';
                 $object->changedValues[$this->databaseInfo->primary] = '';
                 break;
             case RELATION_FOREIGN:
                 if (array_key_exists($this->databaseInfo->primary, $object->databaseInfo->fields)) {
                     $object->changedValues[$this->databaseInfo->primary] = '';
                 } elseif (array_key_exists($object->databaseInfo->primary, $this->databaseInfo->fields)) {
                     $this->changedValues[$object->databaseInfo->primary] = '';
                 }
                 break;
             case RELATION_MANY:
                 $input = dbObject::search($this->relations[$className]->connectorClass, array($object->databaseInfo->primary => $object->databaseInfo->ID, $this->databaseInfo->primary => $this->databaseInfo->ID));
                 // search for a connector with both primaries
                 if ($input) {
                     $input[0]->deleteYourSelf();
                 }
                 break;
             case RELATION_CUSTOM:
                 // determine wich one needs to have the primary key set for the 1:many or many:one relation
                 if ($this->fieldForProperty($this->relations[$className]->sourceProperty) != $this->databaseInfo->primary) {
                     // we don't want to change primary keys. This is a good way to check which value to change
                     $targetval = $this->relations[$className]->targetProperty;
                     $this->changedValues[$this->fieldForProperty($this->relations[$className]->sourceProperty)] = '';
                 } else {
                     $targetval = $this->relations[$className]->sourceProperty;
                     $object->changedValues[$this->relations[$className]->targetProperty] = '';
                 }
                 break;
         }
         $this->Save();
         $object->Save();
     }
 }