Answer the question
In order to leave comments, you need to log in
How to assign null to a field in doctrine2?
Today I encountered the fact that doctrine does not save fields that are assigned null
For example
..
$object->setLockedBy(null);
$object->setLockedAt(null);
..
$em->persist($object);
$em->flush();
As a result, the value of the specified fields does not change. getter and setter standard generated by symfony2
Answer the question
In order to leave comments, you need to log in
Everything works.
Show all the code, where do you get the object from, what config does the entity have
<?php
namespace Backend\WorkorderBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* Workorder
*
* @ORM\Table(name="workorder")
* @ORM\Entity(repositoryClass="Backend\WorkorderBundle\Entity\WorkorderRepository")
*/
class Workorder
{
//..
/**
* @var integer
*
* @ORM\Column(name="locked_by", type="integer", nullable=true)
*/
private $lockedBy;
/**
* @var \DateTime
*
* @ORM\Column(name="locked_at", type="datetime", nullable=true)
*/
private $lockedAt;
//..
public function __construct()
{
//здесь про эти два объекта ничего
}
//..
/**
* Set lockedBy
*
* @param integer $lockedBy
* @return Workorder
*/
public function setLockedBy($lockedBy)
{
$this->lockedBy = $lockedBy;
return $this;
}
/**
* Get lockedBy
*
* @return integer
*/
public function getLockedBy()
{
return $this->lockedBy;
}
//..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question