We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

forUpdate - doesn't work

Hello All.

I found bug in ORM, I think.

I use profiler to view all queries in page. If I use pure sql query:


$phql = "SELECT * FROM general_table where key = '$key' FOR UPDATE;";
$row = Phalcon\DI::getDefault()->getShared('db')->query($phql)->fetch();

logger showes to me - 'SELECT * FROM general_table where key = 'abc' FOR UPDATE;'

If I use model:


$row = Model\General\GeneralTable::findFirst(
            array(
                "limit" => 1,
                "conditions" => 'key= :key:',
                "bind" => array('key'=>$key),
                "for_update" => true
            )
        );

logger showes only: 'SELECT * FROM general_table WHERE key = 'abc'

It's means "FOR UPDATE" doesn't append to query.

Can somebody help to me???

UPDATE: Phalcon 1.3.2

edited May '14

There's 3 ways to do that query, you can try using builder or criteria:

    $row = Model\General\GeneralTable::query()
        ->limit(1)
        ->where('key= :key:', array('key'=>$key))
        ->forUpdate(true)
        ->execute()
        ->getFirst();


43.9k

I've also experimented some un implemented features in the ORM. Maybe ask that as NFR on github ...

Sorry, I forgot write about 3rd way - its also doesn't work.