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

Enum in model update/save is required even though it's already filled

Hi, I'm having strange issue on Phalcon 2.0.X and don't really know how should I even debug it. I've created a simple mysql table made of a few columns. One of them is item_condition column which basicly is an enum with a few options. And here is the problem:

I'm unable to update/save this model because it's constantly returning error message: item_condition is required even though it's already there and remains untouched. It works well after changing that field to varchar so I think that it's some issue with comparing strings of enums (What it says it's basicly that 'State1' from database != 'State1' in model fulfiled from database. What should I do?

edit: looks like this problem is fixed in phalcon 2.1.x



79.0k
Accepted
answer
edited Apr '16

I would suggest you to avoid using ENUM. Especially with ORM. The other way around would be to fill out your Model prior to update, with actual value from ENUM field from database. From my expirience with Phalcon's ORM, that kind of errors can be solved with:

https://docs.phalcon.io/en/latest/reference/models.html#skipping-columns

skipAttributes ()

Sets a list of attributes that must be skipped from the generated INSERT/UPDATE statement

8 Reasons Why MySQL's ENUM Data Type Is Evil https://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/

When you should and should NOT use ENUM data type https://www.cubrid.org/blog/cubrid-life/when-you-should-and-should-not-use-enum-data-type/