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

How to convert a model to "model" when its "incomplete"?

I have this

$robots = Robots::findFirst(3);

$robots->save();

so far so good, but I dont need all fields, so:

$robots = Robots::findFirst(3, array(

  'columns' => 'id, name'

));

$robots->save();

this time ->save() fails. How to get its "complete" object?

Post fixed. Please read the Markdown FAQ for properly formatting code.



17.5k

Is it failing your validation? What is the error?

edited Oct '15

You could try turning on 'useDynamicUpdate' - https://docs.phalcon.io/en/latest/reference/models.html#dynamic-update with the model.

Although I'm not quite sure the actual model class is returned when you specify columns, but rather an object representing the partial database object.

var_dump(get_class(Robots::findFirst(3, ['columns' => 'id, name']));
//If it returns the Model class, then try useDynamicUpdate() - otherwise you'd probably need to do PHQL to update the table.