2011-10-11 2 views
0

Doctrine으로 구성된 Symfony 응용 프로그램이 있고 두 모델 간의 일대 다 관계를 설계했습니다. ItemCustomer에 속합니다. sfGuardUser의 별칭get 마법 메서드를 사용할 때 Doctrine이 NULL 값으로 null을 반환하지 않습니다.

상품에 고객이없는 경우가 있다고 가정 해 보겠습니다. 이를 테스트하기 위해 나는이 비교를 만들려고 노력 해요 :

$customer = $this->getCustomer(); 
if ($customer) { 
    return $customer->getNbInvoices(); 
} 
else { 
    return 'n/a'; 
} 

그러나 $this->getCustomer()과 함께 비교 null 또는 기타 '거짓'값을 반환하지 않습니다, 그리고 외래 키는 데이터베이스에 NULL로 설정됩니다.

데이터베이스의 실제 값을 저장하지 않는 개체를 어떻게 비교할 수 있습니까?

답변

0

방법에 대한

if ($this->relatedExists('Customer') { 
    return $this['Customer']->getNbInvoices(); 
} else { 
    return 'n/a'; 
}