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.

Uneditable entries, problem with relations

I would like to have uneditable entries in my project. This means, based on "editable" field, or other conditions entry may not be updated. I solved this using beforeValidation and beforeDelete, returning false and appending an error message. However this caused problems, when I had those entries as related entities.

E.g. I have some objects, lets say music genres. User can create/update/delete genres, but some of them are default and can not be edited. Now I want to save a song with this genre and I can't, because Phalcon implicitly saves all related entities, and default genres are uneditable.

I could not find any way to check if object has been modified. There are some DIRTY_.. states, but it's unclear what do they actually do.

Does anyone have an idea how can this be achieved without breaking relations?



85.4k
Accepted
answer

You can use the method Phalcon\Mvc\Model::hasChanged to check if a record has been changed with respect the one in the database. You can also activate the dynamic update feature to avoid updating records that haven't changed.