将空值插入日期列

dan*_*son 1 doctrine-orm

如何在Doctrine2中的日期列中插入/更新空值?

我已将日期列设置为nullable = true.

/**
 * @ORM\Column(type="date", nullable=true)
 */
private $dateBar;
Run Code Online (Sandbox Code Playgroud)

我试过这个:

$foo->setDateBar(new \DateTime()); // Inserts today's date
$foo->setDateBar();  // Throws error
Run Code Online (Sandbox Code Playgroud)

我在doctrine2的文档中找不到任何内容.

Cer*_*rad 6

我猜你的setDateBar总是需要一个参数?尝试:

public function setDateBar($date = null)
{
    $this->dateBar = $date;
}
Run Code Online (Sandbox Code Playgroud)

如果这不是问题,那么请发布您的错误消息.