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

Unable to update with confidence just create nonesense

I can't update records. I either get errors or I fill colums up with nulls on a new record (how does that even happen using update?).

So can someone PLEASE tell me how to perform an update with partial data without having a nightmare:

If I have the following in my database

    id              3
    status      "old_status"
    desc        "this is a description"
    year        "2014"

Why won't $this->update(array("id" => 3, "status" => "new_status")) give me:

    id              3
    status      "new_status"
    desc        "this is a description"
    year        "2014"

at the end?

I've tried whitelist and $this->useDynamicUpdate(true); and setting allow nulls in mysql and

\Phalcon\Mvc\Model::setup([
        'notNullValidations' => false
]);

and various combinations but no joy.



10.9k
Accepted
answer

DOH! Just dawned on me. Make sure you are using MyModelName::findFirst($id) not new MyModelName(); in your controller. I was ready to jump of a bridge then!



10.9k

$this->useDynamicUpdate(true); is also being used.