-1
我用Google搜索和所有答案似乎使用查詢生成器建議 - 但我寧願這個值通過實體API設置爲NULL(即:setUsername(空))。將Doctrine實體值設置爲NULL?
這樣做但是將該值設置爲空字符串不是NULL。
有什麼辦法來實現這一目標,而不訴諸實施一個UPDATE查詢?
編輯
$em = $this->getDoctrine()->getManager();
$quote = $em->getRepository('AppBundle:Quote')->findOneByUuid($uuid);
if (null !== $quote) {
$quote->setUuid(null); // *** SET EMPTY STRING NOT RDBMS NULL ***
$em->persist($quote);
$em->flush();
return $this->render('quote/thanks.html.twig');
}
實體
/**
* @ORM\Column(type="string", unique=true, length=36, nullable=false)
*/
private $uuid;
什麼 「這個值」?這個問題目前還不清楚。添加更多相關細節。 – svgrafov
在數據庫中,如果該列的默認值設置爲空字符串,並正在從理論設定值設置爲null,將其值設置爲空字符串不是null –
顯示的'username'字段定義(教義註釋)。 – miikes