2010-11-29 4 views
0

나는 optionnal 인 입력이있는 양식을 가지고 있지만 외래 키이고 Doctrine이 오류를 표시하기 때문에 사용자가 입력하지 않으면 양식을 유효하게 할 수 없습니다.외래 키를 null로 설정하는 방법은 무엇입니까? (symfony)

SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`logements`.`bail`, CONSTRAINT `bail_ibfk_3` FOREIGN KEY (`locataire2`) REFERENCES `locataire` (`nud`) ON DELETE CASCADE ON UPDATE CASCADE) 

내가 phpMyAdmin을 동일한 요청을 시도하고 제대로 작동 : 나는 외래 키가 null로 설정할 수 있습니다.

외래 키를 null로 설정하고 Doctrine 오류없이 양식을 유효하게하려면 어떻게해야합니까?

편집

Bail: 
    connection: doctrine 
    tableName: bail 
    columns: 
    id: 
     type: integer(2) 
     fixed: false 
     unsigned: true 
     primary: true 
     autoincrement: true 
    locataire1: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    locataire2: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    logement: 
     type: integer(2) 
     fixed: false 
     unsigned: true 
     primary: false 
     notnull: false 
     autoincrement: false 
    datedeb: 
     type: date(25) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    datefin: 
     type: date(25) 
     fixed: false 
     unsigned: false 
     primary: false 
     default: '0000-00-00' 
     notnull: false 
     autoincrement: false 
    colloc: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: false 
     default: '0' 
     notnull: false 
     autoincrement: false 
    bailglissant: 
     type: string(12) 
     fixed: false 
     unsigned: false 
     primary: false 
     default: 'Non spécifié' 
     notnull: false 
     autoincrement: false 
    relations: 
    Locataire: 
     local: locataire1 
     foreign: nud 
     type: one 
    Logement: 
     local: logement 
     foreign: id 
     type: one 
    Locataire_3: 
     class: Locataire 
     local: locataire2 
     foreign: nud 
     type: one 
+1

스키마 정의와 양식을 붙여주십시오. 필드가 실제로 선택 사항으로 정의 된 경우 그러한 메시지를 가져서는 안됩니다. 데이터베이스에서 오류가 발생하므로 doctrine이 '0'을 넣으려고합니다. –

+0

내 양식의 위젯은 "locataire2" – Elorfin

답변

0

속성을 NULL로 설정하기 위해 processValues ​​() (save()로 호출) 메소드를 사용하여이 문제를 해결했습니다.

1

나는 경우가 여기에 있는지 확실하지 않습니다하지만 일대일 관계를 위해 당신은 당신이 널 (null)로 설정하려면 Doctrine_Null 개체를 사용해야합니다

$this->setLocataire2(new Doctrine_Null()); 

select 대신에 사용하는 입력으로 인해 문제가 발생할 수 있습니다.

+1

작동하지 않지만이 객체에 대해 감사드립니다. – Elorfin

관련 문제