-1

目前,我正在进行一些与模型相关的改进,并研究我编写的特定查询。

$queryGetPages = $this->fetchAll($this->select()
                        ->where('page_active = ?', (int) $active)
                        ->order('page_rank ASC'));

if($queryGetPages) {
     $queryGetPages = $queryGetPages->toArray();

     foreach($queryGetPages as $key => $value) {
         $queryGetPagePrint = $this->find($value['pageid'])
         ->current()
         ->findModule_Model_ModulePagesPrintsViaModule_Model_ModulePagesFuses(
                                                            $this->select()
                                                            ->from('module_pages_prints', array('print_title'))                             
                                                            ->where('fuse_locale = ?', $this->_toolbox['editor']['translation']) )
    }                                                       
}

问题出在从相关表请求数据的魔术方法中。我只需要每行的“标题”单元格,但由于某种原因它不会让我这样做。即使使用此查询,它也会返回该行中的所有单元格。我做错了什么,但不知道是什么!

如果有人能指出我正确的方向,我将非常感激。

此致 !

4

1 回答 1

1

在您的情况下隐式调用的函数是findManyToManyRowset()(Zend/Db/Table/Row/Abstract.php 中的代码,第 1001-1108 行(从 ZF 1.12.1 开始)。看看第 1070-1072 行:

$select->from(array('i' => $interName), array(), $interSchema)
    ->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
    ->setIntegrityCheck(false);

简而言之:被调用的函数将覆盖您的from()调用并从依赖表 ( module_pages_fuses) 中选择所有行。这就是它的设计工作方式。

相反,我建议您以“愚蠢”的方式编写您实际需要的查询,例如

$queryGetPagePrint = $this->select()
    ->from(array('p' => 'module_pages_prints'), array('print_title'))
    ->join(array('f' => 'module_pages_fuses'),'p.pageid = f.pageid',array())
    ->where('f.fuse_locale = ?', $this->_toolbox['editor']['translation'])
    ->where('p.pageid = ?', $value['pageid']);
于 2013-03-07T13:02:03.263 回答