src/xPDO/Om/xPDOObject.php
public function getGraph($graph = true, $criteria = null, $cacheFlag = true) {
        /* graph is true, get all relations to max depth */
        if ($graph === true) {
            $graph = $this->xpdo->getGraph($this->_class);
        }
        /* graph is an int, get relations to depth of graph */
        if (is_int($graph)) {
            $graph = $this->xpdo->getGraph($this->_class, $graph);
        }
        /* graph defined as JSON, convert to array */
        if (is_string($graph)) {
            $graph= $this->xpdo->fromJSON($graph);
        }
        /* graph as an array */
        if (is_array($graph)) {
            foreach ($graph as $alias => $branch) {
                $fkMeta = $this->getFKDefinition($alias);
                if ($fkMeta) {
                    $fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
                    if ($criteria === null) {
                        $query= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
                        if ($fkCriteria !== null) {
                            $query= array($fkCriteria, $query);
                        }
                    } else {
                        $query= $this->xpdo->newQuery($fkMeta['class'], $criteria);
                        $addCriteria= array("{$query->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
                        if ($fkCriteria !== null) {
                            $fkAddCriteria = array();
                            foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
                                if (is_numeric($fkCritKey)) continue;
                                $fkAddCriteria["{$query->getAlias()}.{$fkCritKey}"] = $fkCritVal;
                            }
                            if (!empty($fkAddCriteria)) {
                                $addCriteria = array($fkAddCriteria, $addCriteria);
                            }
                        }
                        $query->andCondition($addCriteria);
                    }
                    $collection = $this->xpdo->call($fkMeta['class'], 'loadCollectionGraph', array(
                        &$this->xpdo,
                        $fkMeta['class'],
                        $branch,
                        $query,
                        $cacheFlag
                    ));
                    if (!empty($collection)) {
                        if ($fkMeta['cardinality'] == 'many') {
                            $this->_relatedObjects[$alias] = $collection;
                        } else {
                            $this->_relatedObjects[$alias] = reset($collection);
                        }
                    }
                }
            }
        } else {
            $graph = false;
        }
        return $graph;
    }
public function getGraph($graph = true, $criteria = null, $cacheFlag = true) {
        /* graph is true, get all relations to max depth */
        if ($graph === true) {
            $graph = $this->xpdo->getGraph($this->_class);
        }
        /* graph is an int, get relations to depth of graph */
        if (is_int($graph)) {
            $graph = $this->xpdo->getGraph($this->_class, $graph);
        }
        /* graph defined as JSON, convert to array */
        if (is_string($graph)) {
            $graph= $this->xpdo->fromJSON($graph);
        }
        /* graph as an array */
        if (is_array($graph)) {
            foreach ($graph as $alias => $branch) {
                $fkMeta = $this->getFKDefinition($alias);
                if ($fkMeta) {
                    $fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
                    if ($criteria === null) {
                        $query= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
                        if ($fkCriteria !== null) {
                            $query= array($fkCriteria, $query);
                        }
                    } else {
                        $query= $this->xpdo->newQuery($fkMeta['class'], $criteria);
                        $addCriteria= array("{$query->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
                        if ($fkCriteria !== null) {
                            $fkAddCriteria = array();
                            foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
                                if (is_numeric($fkCritKey)) continue;
                                $fkAddCriteria["{$query->getAlias()}.{$fkCritKey}"] = $fkCritVal;
                            }
                            if (!empty($fkAddCriteria)) {
                                $addCriteria = array($fkAddCriteria, $addCriteria);
                            }
                        }
                        $query->andCondition($addCriteria);
                    }
                    $collection = $this->xpdo->call($fkMeta['class'], 'loadCollectionGraph', array(
                        &$this->xpdo,
                        $fkMeta['class'],
                        $branch,
                        $query,
                        $cacheFlag
                    ));
                    if (!empty($collection)) {
                        if ($fkMeta['cardinality'] == 'many') {
                            $this->_relatedObjects[$alias] = $collection;
                        } else {
                            $this->_relatedObjects[$alias] = reset($collection);
                        }
                    }
                }
            }
        } else {
            $graph = false;
        }
        return $graph;
    }
public function getGraph ( $ graph = true , $ criteria = null , $ cacheFlag = true ) { /* graph is true, get all relations to max depth */ if ( $ graph === true ) { $ graph = $ this -> xpdo -> getGraph ( $ this -> _class ) ; } /* graph is an int, get relations to depth of graph */ if ( is_int ( $ graph ) ) { $ graph = $ this -> xpdo -> getGraph ( $ this -> _class , $ graph ) ; } /* graph defined as JSON, convert to array */ if ( is_string ( $ graph ) ) { $ graph = $ this -> xpdo -> fromJSON ( $ graph ) ; } /* graph as an array */ if ( is_array ( $ graph ) ) { foreach ( $ graph as $ alias => $ branch ) { $ fkMeta = $ this -> getFKDefinition ( $ alias ) ; if ( $ fkMeta ) { $ fkCriteria = isset ( $ fkMeta [ 'criteria' ] ) && isset ( $ fkMeta [ 'criteria' ] [ 'foreign' ] ) ? $ fkMeta [ 'criteria' ] [ 'foreign' ] : null ; if ( $ criteria === null ) { $ query = array ( $ fkMeta [ 'foreign' ] => $ this -> get ( $ fkMeta [ 'local' ] ) ) ; if ( $ fkCriteria !== null ) { $ query = array ( $ fkCriteria , $ query ) ; } } else { $ query = $ this -> xpdo -> newQuery ( $ fkMeta [ 'class' ] , $ criteria ) ; $ addCriteria = array ( "{$query->getAlias()}.{$fkMeta['foreign']}" => $ this -> get ( $ fkMeta [ 'local' ] ) ) ; if ( $ fkCriteria !== null ) { $ fkAddCriteria = array ( ) ; foreach ( $ fkCriteria as $ fkCritKey => $ fkCritVal ) { if ( is_numeric ( $ fkCritKey ) ) continue ; $ fkAddCriteria [ "{$query->getAlias()}.{$fkCritKey}" ] = $ fkCritVal ; } if ( ! empty ( $ fkAddCriteria ) ) { $ addCriteria = array ( $ fkAddCriteria , $ addCriteria ) ; } } $ query -> andCondition ( $ addCriteria ) ; } $ collection = $ this -> xpdo -> call ( $ fkMeta [ 'class' ] , 'loadCollectionGraph' , array ( & $ this -> xpdo , $ fkMeta [ 'class' ] , $ branch , $ query , $ cacheFlag ) ) ; if ( ! empty ( $ collection ) ) { if ( $ fkMeta [ 'cardinality' ] == 'many' ) { $ this -> _relatedObjects [ $ alias ] = $ collection ; } else { $ this -> _relatedObjects [ $ alias ] = reset ( $ collection ) ; } } } } } else { $ graph = false ; } return $ graph ; }
Load a graph of related objects to the current object.

@param boolean|string|array|integer $graph An option to tell how to deal with related objects. If integer, will
traverse related objects up to a $graph level of depth and load them to the object.
If an array, will traverse required related object and load them to the object.
If true, will traverse the entire graph and append all related objects to the object (default behavior).
@param xPDOCriteria|array|string|integer $criteria A valid xPDO criteria representation.
@param boolean|integer $cacheFlag Indicates if the objects should be cached and optionally, by specifying an
integer value, for how many seconds.
@return array|boolean The graph that was loaded or false if nothing was loaded.
Load a graph of related objects to the current object .