I'm developing an API and have the following entity:
/**
* Solicitud de registro.
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="DnD\RaHApiBundle\Repository\ApplicationRepository")
*/
class Application
{
public function __construct()
{
$pending = new Event("PENDING", "APPLICATION");
$this->status = new ArrayCollection($pending);
$this->ownsVehicle = false;
$this->resident = true;
$this->timestamp = new DateTime();
}
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"application_info"})
*/
private $id;
...
Notice the constructor. It sets some fields in my entity with their default values. Now my controller's action:
/**
* Crea una nueva solicitud de afiliacion
* @return array
*
* @Post("applications")
* @ParamConverter("application", converter="fos_rest.request_body")
*/
public function postAction(Application $application)
{
$this->applicationsRepo->save($application);
// It has no date, no status, no defaults!!!
$view = $this->view($application, 200);
$view->getSerializationContext()->setSerializeNull(true);
$view->getSerializationContext()->setGroups(array('application_info'));
return $this->viewHandler->handle($view);
}
The $application object doesn't have its default values set, why is this? how can I make the converter call the constructor and set all default values?