pomm-project / ModelManager

Model Manager for the Pomm database framework.
MIT License
66 stars 27 forks source link

Null value casted in string #83

Closed lunika closed 7 years ago

lunika commented 7 years ago

I have a special case where a <null> value in my database is cast as an empty string in my entity. But it's not always the case, it only happens when the entity is loaded from a complex query

screenshot-2017-10-31 symfony profiler 1

On the screenshot it is the subscription_history table. The result is this one :

screenshot-2017-10-31 symfony profiler

and in my database I have this value

screenshot from 2017-10-31 14-56-15

the origin field is null but I have an empty string here. When I load this subscription_history record in a simple query (directly fron the SubscriptionHistoryModel I have no error.

I don't know if it's a foudation or model manager issue

lunika commented 7 years ago

Here is the raw result of the complex query

screenshot from 2017-10-31 15-25-14

chanmix51 commented 7 years ago

Unfortunately this is because the converter uses PHP’s str_getcsv() function in the EntityConverter. This builtin function implement the RFC4180 which has been made to convert CSV to ms-application/excel mime type. This RFC states all fieds are strings hence empty values are treated as empty strings (except for `str_getcsv('') which returns null, see this discussion about it). The only way I see to circumvent this problem would be to re-implement a finite-state CSV parser in PHP that would probably ruin all performance benefits.

lunika commented 7 years ago

Thanks for you answer. For this case I can use a work around and test if the value is empty instead of NULL. It can be NULL or a valid uuid. But your information is good to know :+1: