library/Garp/Db/Table/Row.php
public function findParentRow($parentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
    {
        $db = $this->_getTable()->getAdapter();

        if (is_string($parentTable)) {
            $parentTable = $this->_getTableFromString($parentTable);
        }

        if (!$parentTable instanceof Zend_Db_Table_Abstract) {
            $type = gettype($parentTable);
            if ($type == 'object') {
                $type = get_class($parentTable);
            }
            throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
        }

        // even if we are interacting between a table defined in a class and a
        // table via extension, ensure to persist the definition
        if (($tableDefinition = $this->_table->getDefinition()) !== null
            && ($parentTable->getDefinition() == null)
        ) {
            $parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
        }

        if ($select === null) {
            $select = $parentTable->select();
        } else {
            $select->setTable($parentTable);
        }

        $map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);

        // iterate the map, creating the proper wheres
        for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
            $dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
            $value = $this->_data[$dependentColumnName];
            // Use adapter from parent table to ensure correct query construction
            $parentDb = $parentTable->getAdapter();
            $parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
            $parentColumn = $parentDb->quoteIdentifier($parentTable->getName()) . '.';
            $parentColumn .= $parentDb->quoteIdentifier($parentColumnName, true);
            $parentInfo = $parentTable->info();

            // determine where part
            $type     = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
            $nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
            if ($value === null && $nullable == true) {
                $select->where("$parentColumn IS NULL");
            } elseif ($value === null && $nullable == false) {
                return null;
            } else {
                $select->where("$parentColumn = ?", $value, $type);
            }

        }

        return $parentTable->fetchRow($select);
    }
public function findParentRow($parentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
    {
        $db = $this->_getTable()->getAdapter();

        if (is_string($parentTable)) {
            $parentTable = $this->_getTableFromString($parentTable);
        }

        if (!$parentTable instanceof Zend_Db_Table_Abstract) {
            $type = gettype($parentTable);
            if ($type == 'object') {
                $type = get_class($parentTable);
            }
            throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
        }

        // even if we are interacting between a table defined in a class and a
        // table via extension, ensure to persist the definition
        if (($tableDefinition = $this->_table->getDefinition()) !== null
            && ($parentTable->getDefinition() == null)
        ) {
            $parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
        }

        if ($select === null) {
            $select = $parentTable->select();
        } else {
            $select->setTable($parentTable);
        }

        $map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);

        // iterate the map, creating the proper wheres
        for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
            $dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
            $value = $this->_data[$dependentColumnName];
            // Use adapter from parent table to ensure correct query construction
            $parentDb = $parentTable->getAdapter();
            $parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
            $parentColumn = $parentDb->quoteIdentifier($parentTable->getName()) . '.';
            $parentColumn .= $parentDb->quoteIdentifier($parentColumnName, true);
            $parentInfo = $parentTable->info();

            // determine where part
            $type     = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
            $nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
            if ($value === null && $nullable == true) {
                $select->where("$parentColumn IS NULL");
            } elseif ($value === null && $nullable == false) {
                return null;
            } else {
                $select->where("$parentColumn = ?", $value, $type);
            }

        }

        return $parentTable->fetchRow($select);
    }
public function findParentRow ( $ parentTable , $ ruleKey = null , Zend_Db_Table_Select $ select = null ) { $ db = $ this -> _getTable ( ) -> getAdapter ( ) ; if ( is_string ( $ parentTable ) ) { $ parentTable = $ this -> _getTableFromString ( $ parentTable ) ; } if ( ! $ parentTable instanceof Zend_Db_Table_Abstract ) { $ type = gettype ( $ parentTable ) ; if ( $ type == 'object' ) { $ type = get_class ( $ parentTable ) ; } throw new Zend_Db_Table_Row_Exception ( "Parent table must be a Zend_Db_Table_Abstract, but it is $type" ) ; } // even if we are interacting between a table defined in a class and a // table via extension, ensure to persist the definition if ( ( $ tableDefinition = $ this -> _table -> getDefinition ( ) ) !== null && ( $ parentTable -> getDefinition ( ) == null ) ) { $ parentTable -> setOptions ( array ( Zend_Db_Table_Abstract :: DEFINITION => $ tableDefinition ) ) ; } if ( $ select === null ) { $ select = $ parentTable -> select ( ) ; } else { $ select -> setTable ( $ parentTable ) ; } $ map = $ this -> _prepareReference ( $ this -> _getTable ( ) , $ parentTable , $ ruleKey ) ; // iterate the map, creating the proper wheres for ( $ i = 0 ; $ i < count ( $ map [ Zend_Db_Table_Abstract :: COLUMNS ] ) ; ++ $ i ) { $ dependentColumnName = $ db -> foldCase ( $ map [ Zend_Db_Table_Abstract :: COLUMNS ] [ $ i ] ) ; $ value = $ this -> _data [ $ dependentColumnName ] ; // Use adapter from parent table to ensure correct query construction $ parentDb = $ parentTable -> getAdapter ( ) ; $ parentColumnName = $ parentDb -> foldCase ( $ map [ Zend_Db_Table_Abstract :: REF_COLUMNS ] [ $ i ] ) ; $ parentColumn = $ parentDb -> quoteIdentifier ( $ parentTable -> getName ( ) ) . '.' ; $ parentColumn .= $ parentDb -> quoteIdentifier ( $ parentColumnName , true ) ; $ parentInfo = $ parentTable -> info ( ) ; // determine where part $ type = $ parentInfo [ Zend_Db_Table_Abstract :: METADATA ] [ $ parentColumnName ] [ 'DATA_TYPE' ] ; $ nullable = $ parentInfo [ Zend_Db_Table_Abstract :: METADATA ] [ $ parentColumnName ] [ 'NULLABLE' ] ; if ( $ value === null && $ nullable == true ) { $ select -> where ( "$parentColumn IS NULL" ) ; } elseif ( $ value === null && $ nullable == false ) { return null ; } else { $ select -> where ( "$parentColumn = ?" , $ value , $ type ) ; } } return $ parentTable -> fetchRow ( $ select ) ; }
ATTENTION
This method is copied from Zend_Db_Table_Row_Abstract.
It is altered to add the table name to the WHERE clause. So instead of

WHERE id = 42

the query becomes:

WHERE MyStuff.id = 42

Query a parent table to retrieve the single row matching the current row.

@param string|Zend_Db_Table_Abstract $parentTable
@param string                        OPTIONAL $ruleKey
@param Zend_Db_Table_Select          OPTIONAL $select
@return Zend_Db_Table_Row_Abstract   Query result from $parentTable
@throws Zend_Db_Table_Row_Exception If $parentTable is not a table or is not loadable.
ATTENTION This method is copied from Zend_Db_Table_Row_Abstract . It is altered to add the table name to the WHERE clause . So instead of