Answer the question
In order to leave comments, you need to log in
Set explicitly all default values for fields via php each time an object is created?
Started learning Symfony and Doctrine. I was interested in how to set default values for fields in the database.
Stumbled upon this discussion: https://stackoverflow.com/questions/3376881/defaul... .
The bottom line is that Doctrine has stopped supporting this and you need to do this:
<?php
/**
* @Entity
*/
class myEntity {
/**
* @var string
*
* @Column(name="myColumn", type="string", length="50")
*/
private $myColumn = 'myDefaultValue';
...
}
Answer the question
In order to leave comments, you need to log in
I would use both ways at the same time:
<?php
namespace App\Entity;
/**
* @Entity
*/
class User
{
const DEFAULT_ROLE = 'user';
/**
* @Column(type="string", options={"default": User::DEFAULT_ROLE})
*
* @var string
*/
private $role = self::DEFAULT_ROLE;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question