Example #1
0
 /**
  * Query the records on which the UPDATE/DELETE operation well be done
  *
  * @param \Phalcon\Mvc\Model $model
  * @param array $intermediate
  * @param array $bindParams
  * @param array $bindTypes
  * @return \Phalcon\Mvc\Model\ResultsetInterface
  */
 protected function _getRelatedRecords(Model $model, array $intermediate, array $bindParams, array $bindTypes)
 {
     $selectColumns = array(array(array('type' => 'object', 'model' => get_class($model), 'column' => $model->getSource())));
     //Instead of creating a PHQL string statement, we manually create the IR representation
     $selectIr = array('columns' => $selectColumns, 'models' => $intermediate['models'], 'tables' => $intermediate['tables']);
     //Check if a WHERE clause was especified
     if (isset($intermediate['where']) === true) {
         $selectIr['where'] = $intermediate['where'];
     }
     if (isset($intermediate['limit']) === true) {
         $selectIr['limit'] = $intermediate['limit'];
     }
     //We create another Phalcon\Mvc\Model\Query to get the related records
     $query = new Query();
     $query->setDi($this->_dependencyInjector);
     $query->setType(309);
     $query->setIntermediate($selectIr);
     return $query->execute($bindParams, $bindTypes);
 }
Example #2
0
 public function getQuery()
 {
     if (!$this->_Phql) {
         throw new \Exception('please format sql after call this method');
     }
     $where = $this->getWhere();
     if (!empty($where)) {
         $this->_Phql .= ' WHERE ' . $where;
     }
     $limit = $this->getLimit();
     if (!empty($limit)) {
         $this->_Phql .= ' LIMIT ' . $limit;
     }
     // or new ModelQuery($this->_Phql) call all
     $query = new \Phalcon\Mvc\Model\Query($this->_Phql, \Phalcon\Di::getDefault());
     if (!empty($this->_bindParams)) {
         $query->setBindParams($this->_bindParams);
     }
     if (!empty($this->_bindTypes)) {
         $query->setBindTypes($this->_bindTypes);
     }
     $query->setType($this->_type);
     $query->setDI(\Phalcon\Di::getDefault());
     return $query;
 }