-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs: Remove empty string defaults from entities #1387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not getting the SQL exception in 'Validating Data' section; empty strings are being stored instead of null being attempted. The simplest fix is to remove the default empty strings from the entities. This is using the Symfony and Composer install.
I think it would be better to change only the public ?string $title = null; |
@alanpoulain works for me...I'll update with this |
Allowing null values here is bad DB and entity design IMHO. I would prefer to just change the wording to tell that allowing the user to not fill the title is not what we except, and introduce validation with the |
Not sure what you mean Kevin. The resource is not linked yet to DB. The Doctrine attribute can be not nullable but this one needs to be nullable in order to deserialize it correctly and have a |
I see what Kevin is saying. I you were just designing the table (and not thinking about API's or anything else), you wouldn't allow book.title to be null....it's sort of sacrificing good design just to demonstrate how something else works. |
Exactly! |
But currently (and sadly?) there is no other way to correctly have validation without using for instance DTOs. |
I'm not sure to understand @alanpoulain |
My bad maybe it works since |
@alanpoulain good point...done now 👍 |
I don't think that we must remove the default values (this could trigger "initialized value" exceptions. Couldn't we remove the part about the SQL error and say that sending no values or an empty string doesn't trigger an error while it should? |
OK...I'll change to that. |
Thank you very much @GaryClarke, and sorry for the delay. |
You're welcome @dunglas 🤝 ..even though I'd totally forgot about this 😂 |
I'm not getting the SQL exception in 'Validating Data' section; empty strings are being stored instead of null being attempted.
The simplest fix is to remove the default empty strings from the entities.
This is using the Symfony and Composer install.