-1

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 !

Willem Poortman
  • 121
  • 1
  • 13
  • 1
    `findModule_Model_ModulePagesPrintsViaModule_Model_ModulePagesFuses` is the nastiest function name I've seen so far :D – mingos Mar 07 '13 at 12:09
  • @mingos: I really dont care what you've seen. I'm trying to fix some bugs here... – Willem Poortman Mar 07 '13 at 12:14
  • 3
    Oh, an asker with an attitude! "I don't care what you've seen, give my my f*cking answer, I DESERVE IT". Nice, man, really nice. I was just investigating the issue with intention to offer you a solution, but I've just changed my mind. – mingos Mar 07 '13 at 12:26
  • No problem, someone else will help. I'm sorry for having an attitude, but its just not the right time... – Willem Poortman Mar 07 '13 at 12:36
  • I'm glad to hear that you're sorry. If you're asking for help, please try to be less hostile towards people wanting to help out. We don't get paid to do this and can only receive appreciation in return for the effort. – mingos Mar 07 '13 at 13:04

1 Answers1

1

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']);
mingos
  • 23,778
  • 12
  • 70
  • 107
  • True, I'm not really a big fan of the 'dumb' way haha. I've tried almost the exact same query earlier, but it a bit to dirty (even if you dont like my function names =D). I'm going to dive into this a bit more tonigh. Ill keep the topic open for now. Thanks – Willem Poortman Mar 07 '13 at 14:15
  • 1
    It might seem "dirty" or, but my personal opinion is that it's actually more readable than cryptic function names composed of lng class names. Plus, avoiding the use of `__call` and other magic methods makes the IDE more aware of what you're doing (code completion, return type checking, correctness checks). That's my personal opinion at least. – mingos Mar 07 '13 at 14:35