src/xPDO/Om/xPDOObject.php
protected function _getRelatedObjectsByFK($alias, $criteria= null, $cacheFlag= true) {
        $collection= array ();
        if (isset($this->_relatedObjects[$alias]) && (is_object($this->_relatedObjects[$alias]) || (is_array($this->_relatedObjects[$alias]) && !empty ($this->_relatedObjects[$alias])))) {
            $collection= & $this->_relatedObjects[$alias];
        } else {
            $fkMeta= $this->getFKDefinition($alias);
            if ($fkMeta) {
                $fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
                if ($criteria === null) {
                    $criteria= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
                    if ($fkCriteria !== null) {
                        $criteria= array($fkCriteria, $criteria);
                    }
                } else {
                    $criteria= $this->xpdo->newQuery($fkMeta['class'], $criteria);
                    $addCriteria = array("{$criteria->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
                    if ($fkCriteria !== null) {
                        $fkAddCriteria = array();
                        foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
                            if (is_numeric($fkCritKey)) continue;
                            $fkAddCriteria["{$criteria->getAlias()}.{$fkCritKey}"] = $fkCritVal;
                        }
                        if (!empty($fkAddCriteria)) {
                            $addCriteria = array($fkAddCriteria, $addCriteria);
                        }
                    }
                    $criteria->andCondition($addCriteria);
                }
                if ($collection= $this->xpdo->getCollection($fkMeta['class'], $criteria, $cacheFlag)) {
                    $this->_relatedObjects[$alias]= array_diff_key($this->_relatedObjects[$alias], $collection) + $collection;
                }
            }
        }
        if ($this->xpdo->getDebug() === true) {
            $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "_getRelatedObjectsByFK :: {$alias} :: " . (is_object($criteria) ? print_r($criteria->sql, true)."\n".print_r($criteria->bindings, true) : 'no criteria'));
        }
        return $collection;
    }
protected function _getRelatedObjectsByFK($alias, $criteria= null, $cacheFlag= true) {
        $collection= array ();
        if (isset($this->_relatedObjects[$alias]) && (is_object($this->_relatedObjects[$alias]) || (is_array($this->_relatedObjects[$alias]) && !empty ($this->_relatedObjects[$alias])))) {
            $collection= & $this->_relatedObjects[$alias];
        } else {
            $fkMeta= $this->getFKDefinition($alias);
            if ($fkMeta) {
                $fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
                if ($criteria === null) {
                    $criteria= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
                    if ($fkCriteria !== null) {
                        $criteria= array($fkCriteria, $criteria);
                    }
                } else {
                    $criteria= $this->xpdo->newQuery($fkMeta['class'], $criteria);
                    $addCriteria = array("{$criteria->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
                    if ($fkCriteria !== null) {
                        $fkAddCriteria = array();
                        foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
                            if (is_numeric($fkCritKey)) continue;
                            $fkAddCriteria["{$criteria->getAlias()}.{$fkCritKey}"] = $fkCritVal;
                        }
                        if (!empty($fkAddCriteria)) {
                            $addCriteria = array($fkAddCriteria, $addCriteria);
                        }
                    }
                    $criteria->andCondition($addCriteria);
                }
                if ($collection= $this->xpdo->getCollection($fkMeta['class'], $criteria, $cacheFlag)) {
                    $this->_relatedObjects[$alias]= array_diff_key($this->_relatedObjects[$alias], $collection) + $collection;
                }
            }
        }
        if ($this->xpdo->getDebug() === true) {
            $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "_getRelatedObjectsByFK :: {$alias} :: " . (is_object($criteria) ? print_r($criteria->sql, true)."\n".print_r($criteria->bindings, true) : 'no criteria'));
        }
        return $collection;
    }
protected function _getRelatedObjectsByFK ( $ alias , $ criteria = null , $ cacheFlag = true ) { $ collection = array ( ) ; if ( isset ( $ this -> _relatedObjects [ $ alias ] ) && ( is_object ( $ this -> _relatedObjects [ $ alias ] ) || ( is_array ( $ this -> _relatedObjects [ $ alias ] ) && ! empty ( $ this -> _relatedObjects [ $ alias ] ) ) ) ) { $ collection = & $ this -> _relatedObjects [ $ alias ] ; } else { $ fkMeta = $ this -> getFKDefinition ( $ alias ) ; if ( $ fkMeta ) { $ fkCriteria = isset ( $ fkMeta [ 'criteria' ] ) && isset ( $ fkMeta [ 'criteria' ] [ 'foreign' ] ) ? $ fkMeta [ 'criteria' ] [ 'foreign' ] : null ; if ( $ criteria === null ) { $ criteria = array ( $ fkMeta [ 'foreign' ] => $ this -> get ( $ fkMeta [ 'local' ] ) ) ; if ( $ fkCriteria !== null ) { $ criteria = array ( $ fkCriteria , $ criteria ) ; } } else { $ criteria = $ this -> xpdo -> newQuery ( $ fkMeta [ 'class' ] , $ criteria ) ; $ addCriteria = array ( "{$criteria->getAlias()}.{$fkMeta['foreign']}" => $ this -> get ( $ fkMeta [ 'local' ] ) ) ; if ( $ fkCriteria !== null ) { $ fkAddCriteria = array ( ) ; foreach ( $ fkCriteria as $ fkCritKey => $ fkCritVal ) { if ( is_numeric ( $ fkCritKey ) ) continue ; $ fkAddCriteria [ "{$criteria->getAlias()}.{$fkCritKey}" ] = $ fkCritVal ; } if ( ! empty ( $ fkAddCriteria ) ) { $ addCriteria = array ( $ fkAddCriteria , $ addCriteria ) ; } } $ criteria -> andCondition ( $ addCriteria ) ; } if ( $ collection = $ this -> xpdo -> getCollection ( $ fkMeta [ 'class' ] , $ criteria , $ cacheFlag ) ) { $ this -> _relatedObjects [ $ alias ] = array_diff_key ( $ this -> _relatedObjects [ $ alias ] , $ collection ) + $ collection ; } } } if ( $ this -> xpdo -> getDebug ( ) === true ) { $ this -> xpdo -> log ( xPDO :: LOG_LEVEL_DEBUG , "_getRelatedObjectsByFK :: {$alias} :: " . ( is_object ( $ criteria ) ? print_r ( $ criteria -> sql , true ) . "\n" . print_r ( $ criteria -> bindings , true ) : 'no criteria' ) ) ; } return $ collection ; }
Gets related objects by a foreign key and specified criteria.

@access protected
@param string $alias The alias representing the relationship.
@param mixed $criteria An optional xPDO criteria expression.
@param bool|int Indicates if the saved object(s) should be cached and
optionally, by specifying an integer value, for how many seconds before
expiring.  Overrides the cacheFlag for the object.
@return array A collection of objects matching the criteria.
Gets related objects by a foreign key and specified criteria .