Zend Framework Select Objects And UNION()

前端 未结 6 2004
南旧
南旧 2020-12-30 16:16

I\'m pretty sure this is not possible in Zend Framework (I have searched the Web, the documentation and issue tracker) but I just want to make sure so I\'m asking here.

6条回答
  •  旧巷少年郎
    2020-12-30 17:15

    This practical example shows a function that returns a rowset of either latest or if a available favourite blog entries of a specific year (artwork blog):

    public function fetchBestOf($year)
    {
        $selectLatest = $this->select()->where('isHidden = 0')
                                       ->where('YEAR(dateCreated) = ' . $year)
                                       ->where('isHighlight = 0');
        $selectHighlights = $this->select()->where('isHidden = 0')
                                           ->where('YEAR(dateCreated) = ' . $year)
                                           ->where('isHighlight = 1');
    
        $selectUnion = $this->select()->union(array($selectLatest, $selectHighlights), Zend_Db_Select::SQL_UNION_ALL)
                       ->order('isHighlight DESC')
                       ->order('dateCreated DESC')
                       ->order('workID DESC')
                       ->limit('5');
    
        $rowset = $this->fetchAll($selectUnion);
        return $rowset;
    }
    

提交回复
热议问题