cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Error in SQL while searching with criteria (0.8.0)

Open demkinmaxim opened this issue 13 years ago • 2 comments

Updated to 0.8.0. Using standart code from scaffold. Now gets error

    if ($this->request->isPost()) {
        $query = \Phalcon\Mvc\Model\Criteria::fromInput($this->di, "Product", $_POST);
        $this->session->conditions = $query->getConditions();
    } else { ...

You have an error in your SQL syntax; ... near ':points ORDER BY `product`.`id`' at line 1

SELECT `product`.`id`, `product`.`stock`...
... WHERE `product`.`points` = :points ORDER BY `product`.`id`

Is it a bug, or some change to code is reuqired? Same problem with different tables/models.

demkinmaxim avatar Jan 04 '13 18:01 demkinmaxim

It must be:


if ($this->request->isPost()) {
    $criteria = \Phalcon\Mvc\Model\Criteria::fromInput($this->di, "Product", $_POST);
    $this->session->parameters = $criteria->getParams();
} else {
    //...
}

Product::find($this->session->parameters);

The $criteria->getConditions() only returns the WHERE clause of the query and getParams returns the conditions + the bound parameters.

ghost avatar Jan 04 '13 20:01 ghost

Using the standard code from scaffold produces the error above.

hugoduraes avatar Mar 01 '13 17:03 hugoduraes