Before you can update a model you need to request it from the database.
In the following example you are querying the first record where the value in column col1
equals 123
.
$all = model::findFirst(['col1 = 123']);
// you can also write this like
$all = model::findFirstByCol1(123);
In the background Phalcon will convert the above code to a query, similar to:
SELECT * FROM model WHERE col1 = 123 LIMIT 1;
Now that you have access to the model via $all
, you can alter its attributes:
$all->col2 = null;
If you are done altering $all
, you can update the values in the database:
$all->update(); // or $all->save();
Refer to the Phalcon documentation, if you need more help on working with models.