Is there a good way to be able to update a table which has a natural key in Phalcon?
Consider this table:
people
------
person
created_at
updated_at
We're going to assume that the person field is unique and is the primary key. I try to do the following:
$person = new People();
$person->person = 'Ed';
$person->save();
$personUpdate = People::findFirst('person = "Ed"');
$personUpdate->person = 'Bob';
$person->save();
What Phalcon ends up trying to do is to INSERT a new record, rather than to update the existing record. What I need it to do is to UPDATE ... WHERE person = 'Ed';
Thoughts?
Thanks!
You are doing correct except ...
People::find
find
will prepare to fetch all data.. this means its in array DocumentationYou need to use
findFirst
instead offind