As I've already found out, Doctrine2 "does not support to set the default values in columns through the “DEFAULT” keyword in SQL. ... you can just use your class properties as default values".
class Product
{
// ...
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name = "";
/**
* @var string $sale
*
* @ORM\Column(name="sale", type="boolean")
*/
private $sale = false;
But even when I do this, the generated CRUD forms still require me to fill out all forms. In case of boolean attributes this even means I can only set it to true (i.e. 1
).
Am I doing something wrong?
(I know I can turn the validation off but I'd like a solution to the problem instead of just bypassing it)
Your boolean value need to have nullable set as true:
/**
* @var string $sale
*
* @ORM\Column(name="sale", type="boolean", nullable=true)
*/
private $sale = false;