New attempt to get Model Serializer discussion going

Guys,

In my VERY HUMBLE opinion, the way Phalcon serializes models should change.

Currently, only columns that map to physical database table fields are auto-serialized. This presents a huge problem for Caching algorithms that rely on model serialization. Essentially, once pulled back from the backend storage, your model will miss fields that are set in Model's post-fetch routine.

I propose that Phalcon serializes all properties defined in a model class that's inheriting from Phalcon\Mvc\Model.

More info: https://github.com/phalcon/cphalcon/issues/1285 http://stackoverflow.com/questions/18984972/phalcon-mvc-model-serialization-object-properties-are-lost

Thoughts?

I agree! I deal with simular issues.

Maybe add dummy field ( for eg __cached ) to your table schema, and use this field for caching. This way it will be serialized, and you know that it is dummy field for something :)



31.5k

There is no shortage of tricks, that's for certain. However, fixing the root cause makes it easier for everyone...

edited Mar '14

It make sense because if this virtual columns could be defined in every methods in model it sould be traced on every request? Better way is as i wrote, make any field in table, with any prefix you know for what you use it, describe it in database with comments and it will be clean. I think that it is better clean solutions than an overloaded framework.



31.5k
edited Mar '14

Hi Karol,

Can you explain in simple words why do you think that maintaining an extra column in every model table is cleaner than serializing all model columns?

than an overloaded framework.

What do you mean by that?

Thanks!

Temuri, i had the same problem, dependent on state of one field had to fill field which i want to serialize and find out that it is the best solution i could find that time. You, your team, database designer etc will know that this field exist, is for something (table field comments), without going to definition of your model.

I saw your issue https://github.com/phalcon/cphalcon/issues/1285 and understand that you suppose that if you define variable at model it should be treated as field, but when you want to save(), update() etc there are no field in DB.

Look at my post more than half a year http://forum.phalconphp.com/discussion/498/afterfetch-



6.3k

Is there any good solution for this problem now, I am having the same issue with adding few vitual columns in afterFetch() and I am not able to cache the data.