Zend Framework: Zend_Db_Select - how to join custom subquery table?

后端 未结 2 456
滥情空心
滥情空心 2020-12-17 05:03
$select->joinRight(array(\'i\' => \'(SELECT * FROM images ORDER BY image_id)\'),\'i.ad_id = \'. $main .\'.id\',$imarray);

Like that doesn\'t

相关标签:
2条回答
  • 2020-12-17 05:26

    I feel This is easier to read and navigate...

          $sub = $this->select()
                ->setIntegrityCheck(false)
                ->from(array('i' => 'images'), array('*'))
                ->order('i.image_id');
    
    $select = $this->select()
                 ->setIntegrityCheck(false)
                 ->from(array('m' => 'MAIN_TABLE'), array('*'))
                 ->joinRight(array('i' => $sub), 'i.ad_id = m.id', array('*'));
    
       return $this->select($select);
    
    0 讨论(0)
  • 2020-12-17 05:50

    Use

    $select->joinRight(
        array('i' => new Zend_Db_Expr('(SELECT * FROM images ORDER BY image_id)')),
        'i.ad_id = '. $main .'.id',
        $imarray
    );
    
    0 讨论(0)
提交回复
热议问题