Description
Hi! I posted this in main Symfony repo a few days ago and it was closed because it is not a feature, but I was asked to post it here, so here it is. I am not a Symfony expert yet I want to be, really like it and thank you for it, so I may be wrong, just delete this if so and sorry :)
I am using symfony console make:entity
, lets assume one field is company string, not nullable.
It generates:
public function setCompany(string $company): static
{
$this->company = $company;
return $this;
}
Shouldn't it generate:
public function setCompany(?string $company): static
{
$this->company = $company;
return $this;
}
?
When user submits form with empty company I am getting:
HTTP 500. InvalidArgumentException. Expected argument of type "string", "null" given at property path "company".
The thing is that I have validator on this field, in form, so it checks for NotBlank, but it just does not have oportunity to do its job.
If I forget about that validator I am getting:
HTTP 500. An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'company' cannot be null
so it is ok in that case.
When I add ?
everything works, but I have to do it manually in those setters every time I use that command.