Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework 是否可以在Zend_Db_Select上使用带有join()的_referenceMap?_Zend Framework_Join_Zend Db - Fatal编程技术网

Zend framework 是否可以在Zend_Db_Select上使用带有join()的_referenceMap?

Zend framework 是否可以在Zend_Db_Select上使用带有join()的_referenceMap?,zend-framework,join,zend-db,Zend Framework,Join,Zend Db,例如: class Products extends Zend_Db_Table_Abstract { protected $_name = 'products'; protected $_referenceMap = array( 'Bug' => array( 'columns' => array('bug_id'), 'refTableClass' => '

例如:

class Products extends Zend_Db_Table_Abstract
{
    protected $_name = 'products';

    protected $_referenceMap    = array(
        'Bug' => array(
            'columns'           => array('bug_id'),
            'refTableClass'     => 'Bugs',
            'refColumns'        => array('bug_id')
        )
    );

}

$object = new Products();

$select = $object->select()->from()->Join('Bug');

据我所知,$\u referenceMap不是以这种方式使用的,而是定义完整的join语句$_referenceMap定义表行与其他表的关系

这就是为什么在Zend_db_Table_Row_Abstract中可以找到关联的findDependentRowset()、findManyToManyRowset()和findParentRow()。这些方法创建连接

因此,为了从bug中获取依赖行,使用一个select对象,您可以这样做,假设产品与bug有一对多的关系

class Products extends Zend_Db_Table_Abstract
{
    protected $_name             = 'products';
    protected $_dependentTables  = array('Bugs');
}

class Bugs extends Zend_Db_Table_Abstract
{
    protected $_referenceMap = array(
        'Products' => array(
            'columns'            => array('bug_id')
            ,'refTableClass'     => 'Products'
            ,'refColumns'        => array('bug_id')
        )
    );
}
要获取依赖行,首先必须获取父行

$products = new Products();

$productRow = $products->find(123)
                       ->current();
您可以使用Zend_Db_Select优化联接

$select = $products->select()
                   ->where('foo_bar = ?', 'cheese')
                   ->limit(2);
最后,通过传入select对象而不是规则键来查询依赖行

$bugRowset = $productRow->findDependentRowset('Bugs', 'Products', $select);

我想这会有用的,明天早上我必须检查。

这对一行有用,但对整张桌子(或几行)无效。我通常需要影响多行的查询。。。Zend应该实现Phliplip提到的选项或类似的选项:

$select = $object->select()->from()->Join('Bug');

注意:我的意思是,只使用一个查询(太好了:)就赢得了风滚草徽章!我也在搜索这个答案,或者使用$\u referenceMap执行类似的操作