protected function _saveRelatedObjects() {
        $saved= 0;
        if (!empty ($this->_relatedObjects)) {
            foreach ($this->_relatedObjects as $alias => $ro) {
                $objects= array ();
                if (is_object($ro)) {
                    $primaryKey= $ro->_new ? '__new' : $ro->getPrimaryKey();
                    if (is_array($primaryKey)) $primaryKey= implode('-', $primaryKey);
                    $objects[$primaryKey]= & $ro;
                    $cardinality= 'one';
                }
                elseif (is_array($ro)) {
                    $objects= $ro;
                    $cardinality= 'many';
                }
                if (!empty($objects)) {
                    foreach ($objects as $pk => $obj) {
                        if ($fkMeta= $this->getFKDefinition($alias)) {
                            if ($this->_saveRelatedObject($obj, $fkMeta)) {
                                if ($cardinality == 'many') {
                                    $newPk= $obj->getPrimaryKey();
                                    if (is_array($newPk)) $newPk= implode('-', $newPk);
                                    if ($pk != $newPk) {
                                        $this->_relatedObjects[$alias][$newPk]= $obj;
                                        unset($this->_relatedObjects[$alias][$pk]);
                                    }
                                }
                                $saved++;
                            }
                        }
                    }
                }
            }
        }
        return $saved;
    }