Complex WHERE clauses using the PHP Doctrine ORM

后端 未结 7 1912
长发绾君心
长发绾君心 2020-12-13 09:15

I\'m using the PHP Doctrine ORM to build my queries. However, I can\'t quite seem to figure how to write the following WHERE clause using DQL (Doctrine Query Language):

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 10:15

    andWhere can be summarized as:
    Previously Added Condition(s) Aware WHERE Statement

    You can safely use andWhere inplace of where. (it introduces a very tiny overhead, which is stated below in the 2nd list item.)

    The implementation of andWhere is: (Doctrine 1.2.3)

    public function andWhere($where, $params = array())
    {
        if (is_array($params)) {
            $this->_params['where'] = array_merge($this->_params['where'], $params);
        } else {
            $this->_params['where'][] = $params;
        }
    
        if ($this->_hasDqlQueryPart('where')) {
            $this->_addDqlQueryPart('where', 'AND', true);
        }
    
        return $this->_addDqlQueryPart('where', $where, true);
    }
    

    which can be read as,

    1. Process parameters
    2. append AND statement to where part of the query, if another where statement was added before
    3. append condition

提交回复
热议问题