Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Save overwrites fields to NULL

I am running a very simple ->save on a table. I am passing in an array of the field=>values that I would like to update.

$stream_scene_app = new StreamSceneApps();
$temp = $stream_scene_app->save($vars);

The $vars variable contains only (2) fields (id=>3, status=>"on"). However after the save all the fields with exception of the (2) that are passed in are set to NULL. The status field updates properly for the correct record. How do I get Phalcon to not overwrite fields on a save when they are not passed in? I obviously do not want to pass in every field on an update when I just want to update a single field.

I have looked all over and cannot find an answer to this question. There must be something obvious that I am missing.

I finally found another thread mentioning my problem but no answer for it:

edited Dec '14

Ah. Thank you to the following post.

"Make sure you are using MyModelName::findFirst($id) not new MyModelName(); in your controller." posted by Andy Myers.

So in your controller create a little if else block. If "id" is missing than new MyModelName() else MyModelName::findFirst($id).

Seems sort of inefficent though as you need to run a select on before every save. If someone has a better answer please post.