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

Cannot update using phalcon query and model

I've created a table named 'HrmObjectPropertyValue' with MySQL which contains field "modified-at" that trigger now() each time the table is updated. I try to execute the following query:

UPDATE HrmObjectPropertyValue SET hrm_value_id = '18' WHERE hrm_object_id = '9' AND hrm_property_id = '11'

It never works, the table not updated and the "modified-at" field also not automatically trigger though it returns success. However, it works well if i try to execute the query by using the lower database layer with \Phalcon\Db\Adapter\Pdo\Mysql.



1.2k

The primary key of this table is the combination of 3 fields. Is that the problem ?

If hrmvalueid is one of those fields then yes.



1.2k

Yes it is one of the primary key. So how could i solve this problem?

If hrmvalueid is one of those fields then yes.

Only way to do it is to remove it from hrmvalueid, phalcon doesn't allow to edit field which is primary key.



1.2k

I see it works if i execute the query directly with \Phalcon\Db\Adapter\Pdo\Mysql. However, that query is between transaction (db->begin() , db->commit() ). Is it ok, if i use like that?

It's okay beacause its just pdo adapter, you are not using ORM there. Using object way(models) is creating other query, beacause you are using ORM. Phalcon just don't allow in his ORM to edit primiary keys.