我有一個獨特的字段模型,如下圖所示。問題是這個字段是可選的,當它爲空時,我得到了教條的唯一錯誤信息。Doctrine PHP 1.2 - 如何跳過空字段的唯一驗證
我期待它只驗證'notnull'=> true字段的唯一性。
$this->hasColumn('filename', 'string', 40, array(
'type' => 'string',
'unique' => true,
'length' => '40',
));
在此先感謝您。
編輯:我禁用驗證,它看起來像外地攜帶一個空字符串,而不是空的:
SQLSTATE [23000]:完整性約束衝突:「關鍵「文件名」
1062重複條目」所以現在的問題是:如何在空白值上強制使用空值...
編輯2:我是這樣做的解決方法。 =/
public function preValidate()
{
if(!$this->filename) {
$this->filename = null;
}
}
我假設你正在使用symfony 1.4。否則,這個過程仍然非常相似。 – Slickrick12
偉大的解決方案。但是爲了工作,我換成了$ column = $ this-> getOption('column'); $ column = current($ this-> getOption('column')); beacuse getColumn返回一個數組。 –