src/xPDO/Om/xPDOQuery.php
public function join($class, $alias= '', $type= xPDOQuery::SQL_JOIN_CROSS, $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
        if ($this->xpdo->loadClass($class)) {
            $alias= $alias ? $alias : $class;
            $target= & $this->query['from']['joins'];
            $targetIdx= count($target);
            $target[$targetIdx]= array (
                'table' => $this->xpdo->getTableName($class),
                'class' => $class,
                'alias' => $alias,
                'type' => $type,
                'conditions' => array ()
            );
            if (empty ($conditions)) {
                $fkMeta= $this->xpdo->getFKDefinition($this->_class, $alias);
                if ($fkMeta) {
                    $parentAlias= isset ($this->_alias) ? $this->_alias : $this->_class;
                    $local= $fkMeta['local'];
                    $foreign= $fkMeta['foreign'];
                    $conditions= $this->xpdo->escape($parentAlias) . '.' . $this->xpdo->escape($local) . ' =  ' . $this->xpdo->escape($alias) . '.' . $this->xpdo->escape($foreign);
                    if (isset($fkMeta['criteria']['local'])) {
                        $localCriteria = array();
                        if (is_array($fkMeta['criteria']['local'])) {
                            foreach ($fkMeta['criteria']['local'] as $critKey => $critVal) {
                                if (is_numeric($critKey)) {
                                    $localCriteria[] = $critVal;
                                } else {
                                    $localCriteria["{$this->_class}.{$critKey}"] = $critVal;
                                }
                            }
                        }
                        if (!empty($localCriteria)) {
                            $conditions = array($localCriteria, $conditions);
                        }
                        $foreignCriteria = array();
                        if (is_array($fkMeta['criteria']['foreign'])) {
                            foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
                                if (is_numeric($critKey)) {
                                    $foreignCriteria[] = $critVal;
                                } else {
                                    $foreignCriteria["{$parentAlias}.{$critKey}"] = $critVal;
                                }
                            }
                        }
                        if (!empty($foreignCriteria)) {
                            $conditions = array($foreignCriteria, $conditions);
                        }
                    }
                }
            }
            $this->condition($target[$targetIdx]['conditions'], $conditions, $conjunction, $binding, $condGroup);
        }
        return $this;
    }
public function join($class, $alias= '', $type= xPDOQuery::SQL_JOIN_CROSS, $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
        if ($this->xpdo->loadClass($class)) {
            $alias= $alias ? $alias : $class;
            $target= & $this->query['from']['joins'];
            $targetIdx= count($target);
            $target[$targetIdx]= array (
                'table' => $this->xpdo->getTableName($class),
                'class' => $class,
                'alias' => $alias,
                'type' => $type,
                'conditions' => array ()
            );
            if (empty ($conditions)) {
                $fkMeta= $this->xpdo->getFKDefinition($this->_class, $alias);
                if ($fkMeta) {
                    $parentAlias= isset ($this->_alias) ? $this->_alias : $this->_class;
                    $local= $fkMeta['local'];
                    $foreign= $fkMeta['foreign'];
                    $conditions= $this->xpdo->escape($parentAlias) . '.' . $this->xpdo->escape($local) . ' =  ' . $this->xpdo->escape($alias) . '.' . $this->xpdo->escape($foreign);
                    if (isset($fkMeta['criteria']['local'])) {
                        $localCriteria = array();
                        if (is_array($fkMeta['criteria']['local'])) {
                            foreach ($fkMeta['criteria']['local'] as $critKey => $critVal) {
                                if (is_numeric($critKey)) {
                                    $localCriteria[] = $critVal;
                                } else {
                                    $localCriteria["{$this->_class}.{$critKey}"] = $critVal;
                                }
                            }
                        }
                        if (!empty($localCriteria)) {
                            $conditions = array($localCriteria, $conditions);
                        }
                        $foreignCriteria = array();
                        if (is_array($fkMeta['criteria']['foreign'])) {
                            foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
                                if (is_numeric($critKey)) {
                                    $foreignCriteria[] = $critVal;
                                } else {
                                    $foreignCriteria["{$parentAlias}.{$critKey}"] = $critVal;
                                }
                            }
                        }
                        if (!empty($foreignCriteria)) {
                            $conditions = array($foreignCriteria, $conditions);
                        }
                    }
                }
            }
            $this->condition($target[$targetIdx]['conditions'], $conditions, $conjunction, $binding, $condGroup);
        }
        return $this;
    }
public function join ( $ class , $ alias = '' , $ type = xPDOQuery :: SQL_JOIN_CROSS , $ conditions = array ( ) , $ conjunction = xPDOQuery :: SQL_AND , $ binding = null , $ condGroup = 0 ) { if ( $ this -> xpdo -> loadClass ( $ class ) ) { $ alias = $ alias ? $ alias : $ class ; $ target = & $ this -> query [ 'from' ] [ 'joins' ] ; $ targetIdx = count ( $ target ) ; $ target [ $ targetIdx ] = array ( 'table' => $ this -> xpdo -> getTableName ( $ class ) , 'class' => $ class , 'alias' => $ alias , 'type' => $ type , 'conditions' => array ( ) ) ; if ( empty ( $ conditions ) ) { $ fkMeta = $ this -> xpdo -> getFKDefinition ( $ this -> _class , $ alias ) ; if ( $ fkMeta ) { $ parentAlias = isset ( $ this -> _alias ) ? $ this -> _alias : $ this -> _class ; $ local = $ fkMeta [ 'local' ] ; $ foreign = $ fkMeta [ 'foreign' ] ; $ conditions = $ this -> xpdo -> escape ( $ parentAlias ) . '.' . $ this -> xpdo -> escape ( $ local ) . ' =  ' . $ this -> xpdo -> escape ( $ alias ) . '.' . $ this -> xpdo -> escape ( $ foreign ) ; if ( isset ( $ fkMeta [ 'criteria' ] [ 'local' ] ) ) { $ localCriteria = array ( ) ; if ( is_array ( $ fkMeta [ 'criteria' ] [ 'local' ] ) ) { foreach ( $ fkMeta [ 'criteria' ] [ 'local' ] as $ critKey => $ critVal ) { if ( is_numeric ( $ critKey ) ) { $ localCriteria [ ] = $ critVal ; } else { $ localCriteria [ "{$this->_class}.{$critKey}" ] = $ critVal ; } } } if ( ! empty ( $ localCriteria ) ) { $ conditions = array ( $ localCriteria , $ conditions ) ; } $ foreignCriteria = array ( ) ; if ( is_array ( $ fkMeta [ 'criteria' ] [ 'foreign' ] ) ) { foreach ( $ fkMeta [ 'criteria' ] [ 'foreign' ] as $ critKey => $ critVal ) { if ( is_numeric ( $ critKey ) ) { $ foreignCriteria [ ] = $ critVal ; } else { $ foreignCriteria [ "{$parentAlias}.{$critKey}" ] = $ critVal ; } } } if ( ! empty ( $ foreignCriteria ) ) { $ conditions = array ( $ foreignCriteria , $ conditions ) ; } } } } $ this -> condition ( $ target [ $ targetIdx ] [ 'conditions' ] , $ conditions , $ conjunction , $ binding , $ condGroup ) ; } return $ this ; }
Join a table represented by the specified class.

@param string $class The classname (or relation alias for aggregates and
composites) of representing the table to be joined.
@param string $alias An optional alias to represent the joined table in
the constructed query.
@param string $type The type of join to perform.  See the xPDOQuery::SQL_JOIN
constants.
@param mixed $conditions Conditions of the join specified in any xPDO
compatible criteria object or expression.
@param string $conjunction A conjunction to be applied to the condition
or conditions supplied.
@param array $binding Optional bindings to accompany the conditions.
@param int $condGroup An optional identifier for adding the conditions
to a specific set of conjoined expressions.
@return xPDOQuery Returns the current object for convenience.
Join a table represented by the specified class .