Cphalcon: [BUG]: QueryBuilder bug?when column starts with 'not'

Created on 5 Apr 2020  路  7Comments  路  Source: phalcon/cphalcon

$builder = $this
        ->modelsManager
        ->createBuilder()
        ->from(Notice::class)
        ->where("notice_category_id = $id")
        ->orderBy("id desc");

then error message shows like this :

Column 'ice_category_id' doesn't belong to any of the selected models.....

notice's 'not'is gone...combine where not ice_category_id
is this a bug ,or I used QueryBuilder by wrong way?

bug unverified

Most helpful comment

@TimurFlush
ok.I see.Thanks for your answer.

All 7 comments

phalcon version is 4.0.4

Please see the https://github.com/phalcon/cphalcon/issues/14918

You should use the PHQL escaping to fix your issue (and placeholders to avoid the SQL Injection) :

->where('[notice_category_id] = :id:', ['id' => $id]) ;

P.S. I always recommend to use the PHQL escaping

@TimurFlush
ok.I see.Thanks for your answer.

I'm happy to see someone did open a ticket already. I can confirm this bug, and also the woraround to fix it (use the escapers []). While escapers are recommended, but not required, this should be considered a bug.
I'm using Phalcon 4.0.6

It seems the problem is in PHQL parser, in \Phalcon\Mvc\Model\Query\Lang::parsePHQL(), therefore in internal phql_parse_phql(), and... C is not my land... At least for now :smile:
Quickest way to reproduce the bug:
image

I also got this error by naming a column "notes".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mynameisbogdan picture mynameisbogdan  路  3Comments

bestirani2 picture bestirani2  路  3Comments

ismail0234 picture ismail0234  路  3Comments

kkstun picture kkstun  路  3Comments

masood09 picture masood09  路  4Comments