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
 /**
  * Creates a \Phalcon\Mvc\Model\Query and execute it
  *
  * @param string $phql
  * @param array|null $placeholders
  * @return \Phalcon\Mvc\Model\QueryInterface
  * @throws Exception
  */
 public function executeQuery($phql, $placeholders = null)
 {
     if (is_string($phql) === false || is_array($placeholders) === false && is_null($placeholders) === false) {
         throw new Exception('Invalid parameter type.');
     }
     if (is_object($this->_dependencyInjector) === false) {
         throw new Exception('A dependency injection object is required to access ORM services');
     }
     //Create a query
     $query = new Query($phql);
     $query->setDi($this->_dependencyInjector);
     $this->_lastQuery = $query;
     //Execute the query
     return $query->execute($placeholders);
 }