philiplb / CRUDlex

CRUDlex is an easy to use CRUD generator for Symfony 4 and Silex 2 which is great for auto generated admin pages
https://philiplb.de/crudlex/
MIT License
109 stars 23 forks source link

EntityDefinition@getField $default parameter should not be null #99

Open planeth44 opened 6 years ago

planeth44 commented 6 years ago

when you submit a form and fields are not required –if the type is text– the values are an empty string. the getField function replace these empty string value by a null value which breaks the SQL schema of NOT NULL if the definition is VARCHAR

philiplb commented 6 years ago

Hi, the idea of the required-flag is to reflect the NOT NULL constraint. It is called "required" due to the possibility to have non SQL-implementations. My practice is: required = true -> NOT NULL required = false -> NULLABLE Setting empty strings to NULL here is just a choice because I can't decide whether the user wants NULL or empty string with just an input field. A specific use case would be very good where this scheme breaks. I could then think about how an UI supporting the difference between null and empty string could look like.

planeth44 commented 6 years ago

This makes sense. My workaround is to make my custom MySQLDataFactory so I can add a ‘resetToBlank‘ function when calling ‘setValuesAndParameters’. Is there a better way?

As for a suggestion, could you make it a parameter –blank is empty string– in the MySQLDataFactory just like the useUUIDs?

philiplb commented 6 years ago

Adding a flag to the field in the YAML is a good idea, I will do that. Right after the release of 0.14.0 which abstracts out the framework and then there are packages for framework implementations, Silex and Symfony for now. Reason: Silex is end of live. :(

planeth44 commented 6 years ago

👍 Looking forward to the release of 14.0. Any ETA?

philiplb commented 6 years ago

Mainly writing documentation is left. We are currently porting a bigger project to symfony4 and as soon as this works completly, I can be sure that the abstractions are fine.