library/Garp/Content/Manager.php
protected function _addJoinClause(Zend_Db_Select $select, array $related, $rule = null,
        $bindingModel = null, $bidirectional = true
    ) {
        foreach ($related as $filterModelName => $filterValue) {
            $fieldInfo = explode('.', $filterModelName, 2);
            $filterModelName = Garp_Content_Api::modelAliasToClass($fieldInfo[0]);

            $filterColumn = $fieldInfo[1];
            $filterModel = new $filterModelName();
            /**
             * Determine wether a negation clause (e.g. !=) is requested
             * and normalize the filterColumn.
             */
            $negation = strpos($filterColumn, '<>') !== false;
            $filterColumn = str_replace(' <>', '', $filterColumn);

            if ($filterModelName === get_class($this->_model)) {
                /*  This is a homophile relation and the current condition touches the
                    homophile model.
                    The following condition prevents a 'relatable' list to include the
                    current record, because a record cannot be related to itself.
                */
                $select->where(
                    $this->_getTableName($filterModel) . '.' . $filterColumn . ' != ?',
                    $filterValue
                );
            }

            try {
                // the other model is a child
                $reference = $filterModel->getReference(get_class($this->_model), $rule);
                $this->_addHasManyClause(
                    array(
                    'select'        => $select,
                    'filterModel'   => $filterModel,
                    'reference'     => $reference,
                    'filterColumn'  => $filterColumn,
                    'filterValue'   => $filterValue,
                    'negation'      => $negation
                    )
                );
            } catch (Zend_Db_Table_Exception $e) {
                try {
                    // the other model is the parent
                    $reference = $this->_model->getReference(get_class($filterModel), $rule);
                    $this->_addBelongsToClause(
                        array(
                        'select'        => $select,
                        'reference'     => $reference,
                        'filterColumn'  => $filterColumn,
                        'filterValue'   => $filterValue,
                        'negation'      => $negation
                        )
                    );
                } catch (Zend_Db_Table_Exception $e) {
                    try {
                        // the models are equal; a binding model is needed
                        $this->_addHasAndBelongsToManyClause(
                            array(
                            'select'        => $select,
                            'filterModel'   => $filterModel,
                            'filterColumn'  => $filterColumn,
                            'filterValue'   => $filterValue,
                            'negation'      => $negation,
                            'bindingModel'  => $bindingModel,
                            'bidirectional' => $bidirectional
                            )
                        );
                    } catch (Zend_Db_Table_Exception $e) {
                        throw $e;
                    }
                }
            }
        }
    }
protected function _addJoinClause(Zend_Db_Select $select, array $related, $rule = null,
        $bindingModel = null, $bidirectional = true
    ) {
        foreach ($related as $filterModelName => $filterValue) {
            $fieldInfo = explode('.', $filterModelName, 2);
            $filterModelName = Garp_Content_Api::modelAliasToClass($fieldInfo[0]);

            $filterColumn = $fieldInfo[1];
            $filterModel = new $filterModelName();
            /**
             * Determine wether a negation clause (e.g. !=) is requested
             * and normalize the filterColumn.
             */
            $negation = strpos($filterColumn, '<>') !== false;
            $filterColumn = str_replace(' <>', '', $filterColumn);

            if ($filterModelName === get_class($this->_model)) {
                /*  This is a homophile relation and the current condition touches the
                    homophile model.
                    The following condition prevents a 'relatable' list to include the
                    current record, because a record cannot be related to itself.
                */
                $select->where(
                    $this->_getTableName($filterModel) . '.' . $filterColumn . ' != ?',
                    $filterValue
                );
            }

            try {
                // the other model is a child
                $reference = $filterModel->getReference(get_class($this->_model), $rule);
                $this->_addHasManyClause(
                    array(
                    'select'        => $select,
                    'filterModel'   => $filterModel,
                    'reference'     => $reference,
                    'filterColumn'  => $filterColumn,
                    'filterValue'   => $filterValue,
                    'negation'      => $negation
                    )
                );
            } catch (Zend_Db_Table_Exception $e) {
                try {
                    // the other model is the parent
                    $reference = $this->_model->getReference(get_class($filterModel), $rule);
                    $this->_addBelongsToClause(
                        array(
                        'select'        => $select,
                        'reference'     => $reference,
                        'filterColumn'  => $filterColumn,
                        'filterValue'   => $filterValue,
                        'negation'      => $negation
                        )
                    );
                } catch (Zend_Db_Table_Exception $e) {
                    try {
                        // the models are equal; a binding model is needed
                        $this->_addHasAndBelongsToManyClause(
                            array(
                            'select'        => $select,
                            'filterModel'   => $filterModel,
                            'filterColumn'  => $filterColumn,
                            'filterValue'   => $filterValue,
                            'negation'      => $negation,
                            'bindingModel'  => $bindingModel,
                            'bidirectional' => $bidirectional
                            )
                        );
                    } catch (Zend_Db_Table_Exception $e) {
                        throw $e;
                    }
                }
            }
        }
    }
protected function _addJoinClause ( Zend_Db_Select $ select , array $ related , $ rule = null , $ bindingModel = null , $ bidirectional = true ) { foreach ( $ related as $ filterModelName => $ filterValue ) { $ fieldInfo = explode ( '.' , $ filterModelName , 2 ) ; $ filterModelName = Garp_Content_Api :: modelAliasToClass ( $ fieldInfo [ 0 ] ) ; $ filterColumn = $ fieldInfo [ 1 ] ; $ filterModel = new $ filterModelName ( ) ; /**
             * Determine wether a negation clause (e.g. !=) is requested
             * and normalize the filterColumn.
             */ $ negation = strpos ( $ filterColumn , '<>' ) !== false ; $ filterColumn = str_replace ( ' <>' , '' , $ filterColumn ) ; if ( $ filterModelName === get_class ( $ this -> _model ) ) { /*  This is a homophile relation and the current condition touches the
                    homophile model.
                    The following condition prevents a 'relatable' list to include the
                    current record, because a record cannot be related to itself.
                */ $ select -> where ( $ this -> _getTableName ( $ filterModel ) . '.' . $ filterColumn . ' != ?' , $ filterValue ) ; } try { // the other model is a child $ reference = $ filterModel -> getReference ( get_class ( $ this -> _model ) , $ rule ) ; $ this -> _addHasManyClause ( array ( 'select' => $ select , 'filterModel' => $ filterModel , 'reference' => $ reference , 'filterColumn' => $ filterColumn , 'filterValue' => $ filterValue , 'negation' => $ negation ) ) ; } catch ( Zend_Db_Table_Exception $ e ) { try { // the other model is the parent $ reference = $ this -> _model -> getReference ( get_class ( $ filterModel ) , $ rule ) ; $ this -> _addBelongsToClause ( array ( 'select' => $ select , 'reference' => $ reference , 'filterColumn' => $ filterColumn , 'filterValue' => $ filterValue , 'negation' => $ negation ) ) ; } catch ( Zend_Db_Table_Exception $ e ) { try { // the models are equal; a binding model is needed $ this -> _addHasAndBelongsToManyClause ( array ( 'select' => $ select , 'filterModel' => $ filterModel , 'filterColumn' => $ filterColumn , 'filterValue' => $ filterValue , 'negation' => $ negation , 'bindingModel' => $ bindingModel , 'bidirectional' => $ bidirectional ) ) ; } catch ( Zend_Db_Table_Exception $ e ) { throw $ e ; } } } } }
Add a JOIN clause to a Zend_Db_Select object

@param Zend_Db_Select $select The select object
@param array $related Collection of related models
@param string $rule Used to figure out the relationship metadata from the referencemap
@param string $bindingModel Binding model used in HABTM relations
@param bool $bidirectional
@return void
Add a JOIN clause to a Zend_Db_Select object