我有一個配置了Doctrine的Symfony應用程序,並且我設計了兩個模型之間的一對多關係:Item
屬於Customer
,它是sfGuardUser
的別名。當您使用獲取魔術方法時,Doctrine不會返回空值爲NULL
假設某些情況下某件物品沒有任何顧客。爲了測試這個,我試圖使這種比較:
$customer = $this->getCustomer();
if ($customer) {
return $customer->getNbInvoices();
}
else {
return 'n/a';
}
然而$this->getCustomer()
不返回null
或任何其他「假」值與比較,以及外鍵設置爲NULL在數據庫中。
如何比較數據庫中沒有存儲實際值的對象?