src/xPDO/Om/xPDOObject.php
public function addMany(& $obj, $alias= '') {
        $added= false;
        if (!is_array($obj)) {
            if (is_object($obj)) {
                if (empty ($alias)) {
                    if ($obj->_alias == $obj->_class) {
                        $aliases = $this->_getAliases($obj->_class, 1);
                        if (!empty($aliases)) {
                            $obj->_alias = reset($aliases);
                        }
                    }
                    $alias= $obj->_alias;
                }
                if ($fkMeta= $this->getFKDefinition($alias)) {
                    $obj->_alias= $alias;
                    if ($fkMeta['cardinality'] === 'many') {
                        if ($obj->_new) {
                            $objpk= '__new' . (isset ($this->_relatedObjects[$alias]) ? count($this->_relatedObjects[$alias]) : 0);
                        } else {
                            $objpk= $obj->getPrimaryKey();
                            if (is_array($objpk)) {
                                $objpk= implode('-', $objpk);
                            }
                        }
                        $this->_relatedObjects[$alias][$objpk]= $obj;
                        if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Added related object with alias: ' . $alias . ' and pk: ' . $objpk . "\n" . print_r($obj->toArray('', true), true));
                        $added= true;
                    }
                }
            }
        } else {
            foreach ($obj as $o) {
                $added= $this->addMany($o, $alias);
            }
        }
        return $added;
    }
public function addMany(& $obj, $alias= '') {
        $added= false;
        if (!is_array($obj)) {
            if (is_object($obj)) {
                if (empty ($alias)) {
                    if ($obj->_alias == $obj->_class) {
                        $aliases = $this->_getAliases($obj->_class, 1);
                        if (!empty($aliases)) {
                            $obj->_alias = reset($aliases);
                        }
                    }
                    $alias= $obj->_alias;
                }
                if ($fkMeta= $this->getFKDefinition($alias)) {
                    $obj->_alias= $alias;
                    if ($fkMeta['cardinality'] === 'many') {
                        if ($obj->_new) {
                            $objpk= '__new' . (isset ($this->_relatedObjects[$alias]) ? count($this->_relatedObjects[$alias]) : 0);
                        } else {
                            $objpk= $obj->getPrimaryKey();
                            if (is_array($objpk)) {
                                $objpk= implode('-', $objpk);
                            }
                        }
                        $this->_relatedObjects[$alias][$objpk]= $obj;
                        if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Added related object with alias: ' . $alias . ' and pk: ' . $objpk . "\n" . print_r($obj->toArray('', true), true));
                        $added= true;
                    }
                }
            }
        } else {
            foreach ($obj as $o) {
                $added= $this->addMany($o, $alias);
            }
        }
        return $added;
    }
public function addMany ( & $ obj , $ alias = '' ) { $ added = false ; if ( ! is_array ( $ obj ) ) { if ( is_object ( $ obj ) ) { if ( empty ( $ alias ) ) { if ( $ obj -> _alias == $ obj -> _class ) { $ aliases = $ this -> _getAliases ( $ obj -> _class , 1 ) ; if ( ! empty ( $ aliases ) ) { $ obj -> _alias = reset ( $ aliases ) ; } } $ alias = $ obj -> _alias ; } if ( $ fkMeta = $ this -> getFKDefinition ( $ alias ) ) { $ obj -> _alias = $ alias ; if ( $ fkMeta [ 'cardinality' ] === 'many' ) { if ( $ obj -> _new ) { $ objpk = '__new' . ( isset ( $ this -> _relatedObjects [ $ alias ] ) ? count ( $ this -> _relatedObjects [ $ alias ] ) : 0 ) ; } else { $ objpk = $ obj -> getPrimaryKey ( ) ; if ( is_array ( $ objpk ) ) { $ objpk = implode ( '-' , $ objpk ) ; } } $ this -> _relatedObjects [ $ alias ] [ $ objpk ] = $ obj ; if ( $ this -> xpdo -> getDebug ( ) === true ) $ this -> xpdo -> log ( xPDO :: LOG_LEVEL_DEBUG , 'Added related object with alias: ' . $ alias . ' and pk: ' . $ objpk . "\n" . print_r ( $ obj -> toArray ( '' , true ) , true ) ) ; $ added = true ; } } } } else { foreach ( $ obj as $ o ) { $ added = $ this -> addMany ( $ o , $ alias ) ; } } return $ added ; }
Adds an object or collection of objects related to this class.

This method adds an object or collection of objects in a one-to-
many foreign key relationship with this object to the internal list of
related objects.  By adding these related objects, you can cascade
{@link xPDOObject::save()}, {@link xPDOObject::remove()}, and other
operations based on the type of relationships defined.

@see xPDOObject::addOne()
@see xPDOObject::getOne()
@see xPDOObject::getMany()

@param mixed &$obj A single object or collection of objects to be related
to this instance via the intersection class.
@param string $alias An optional alias, required only for instances where
you have more than one relation defined to the same class.
@return boolean Indicates if the addMany was successful.
Adds an object or collection of objects related to this class .