Skip to content

Instantly share code, notes, and snippets.

Created August 28, 2010 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/554965 to your computer and use it in GitHub Desktop.
Save anonymous/554965 to your computer and use it in GitHub Desktop.
<?php
// Zend Framework Workaround
require_once('ZFWA\Db\Table\Row\Abstract.php');
require_once('ZFWA\Db\Table\Select\ColumnsWithoutFrom.php');
// That Table we want to start from
require_once('ThatTable.php');
// init Table
$ThatTable = new ThatTable();
// fetch Rowset/Row
$ThatRowset = $ThatTable->find(1);
$ThatRow = $ThatRowset->current();
// select Intersection Columns
$select = $ThatTable->selectIntersectionColumns('status');
// fetch ManyToMany with Intersection Columns
$FarRows = $ThatRow->findManyToManyRowset('ThatToFarTable', 'FarTable', null, null, $select);
<?php
/**
* @see Zend_Db_Table_Row_Abstract
*/
require_once 'Zend/Db/Table/Row/Abstract.php';
/**
* @category ZFWA
* @package ZFWA_Db
* @subpackage Table
*
* @author Christoph Roensch
*/
abstract class ZFWA_Db_Table_Row_Abstract extends Zend_Db_Table_Row_Abstract
{
/**
* Select columns of the intersection table used in findManyToManyRowset
*
* part of the fix to revert the changes in ZF-3709
*
* @param array|string|Zend_Db_Expr $cols The columns to select.
*/
public function selectIntersectionColumns($cols = '*')
{
if( is_array($cols) )
{
foreach( $cols as &$col )
{
$col = 'i.'.$col;
}
}
elseif ( is_string($cols) )
{
$cols = 'i.'.$cols;
}
$table = $this->getTable();
/**
* @see ZFWA_Db_Table_Select_ColumnsWithoutFrom
*/
require_once 'ZFWA/Db/Table/Select/ColumnsWithoutFrom.php';
$select = new ZFWA_Db_Table_Select_ColumnsWithoutFrom($table);
return $select->columns($cols);
}
}
<?php
/**
* Class for SQL SELECT query manipulation for the Zend_Db_Table_Row component.
*
* allows to use columns before specifying a FROM clause
* part of the fix to revert the changes in ZF-3709
*
* @see ZFWA_Db_Table_Row_Abstract::selectIntersectionColumns()
*
* @category ZFWA
* @package ZFWA_Db
* @subpackage Table
*
* @author Christoph Roensch
*/
class ZFWA_Db_Table_Select_ColumnsWithoutFrom extends Zend_Db_Table_Select
{
/**
* Specifies columns even if they are not used in the FROM clause.
*
* The parameter can be a single string or Zend_Db_Expr object,
* or else an array of strings or Zend_Db_Expr objects.
*
* @param array|string|Zend_Db_Expr $cols The columns to select from this table.
* @param string $correlationName Correlation name of target table. OPTIONAL
* @return ZFWA_Db_Table_Select This ZFWA_Db_Table_Select object.
*/
public function columns($cols = '*', $correlationName = null)
{
$this->_tableCols($correlationName, $cols);
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment