Currently I'm working on a couple of model related improvements and looking into a specific query I've wrote.
$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']) )
}
}
The problem is in the magic method which is requesting data from a related table. I only need the 'title' cell per row, but for some reason it wont let me. Even with this query, it returns all cells from the row. I'm doing something wrong, but have no idea what!
If someone can point me to the right direction, I would be very thankfull.
Best regards !
The function that is implicitly called in your case is findManyToManyRowset()
(code available in Zend/Db/Table/Row/Abstract.php, lines 1001-1108 (as of ZF 1.12.1). Have a look at lines 1070-1072:
$select->from(array('i' => $interName), array(), $interSchema)
->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
->setIntegrityCheck(false);
In short: the function that is called will overwrite your from()
call and select all rows from the dependent table (module_pages_fuses
). This is the way it's designed to work.
Instead, I would recommend writing the query you actually need the "dumb" way, e.g.
$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']);