2011-04-07 28 views
0

我試圖更新processForm()中的外鍵並獲取此錯誤。 這是一個有效的值 我可以設置值,正常的場沒有問題,當我嘗試更新外鍵無法調用Doctrine_Core :: set(),第二個參數應該是Doctrine_Record或Doctrine_Null設置一對一參考時的實例

這樣,我的錯誤,我只得到這個錯誤:

$form->getObject()->setPriority(1); 

這樣我沒有錯誤,但不會太工作:

$form->getObject()->setPriorityId(1); 

模式:

schedule: 
    columns: 
    id: 
     primary: true 
     type: integer 
     notnull: true 
     autoincrement: true 
    sdate: 
     type: date 
     notnull: true 
    stime: 
     type: time 
     notnull: true 
    scope: 
     default: 1 
     type: boolean 
    schedule_count: 
     default: 0 
     type: integer(4) 
    reschedule_justify: 
     type: string 
    priority_id: 
     type: integer 
     notnull: true 
    schedule_type_id: 
     type: integer 
     notnull: true 
    pending_id: 
     default: NULL 
     type: integer 
    cancelled_id: 
     default: NULL 
     type: integer 
    scheduled_by: 
     type: integer 
     notnull: true 
    in_charge: 
     type: integer 
     notnull: true 
    so_id: 
     unique: true 
     type: integer 
     notnull: true 
    relations: 
    priority: 
     local: priority_id 
     foreign: id 
    scheduleType: 
     local: schedule_type_id 
     foreign: id 
    cancelled: 
     onDelete: SET NULL 
     local: cancelled_id 
     foreign: id 
    pending: 
     onDelete: SET NULL 
     local: pending_id 
     foreign: id 
    ScheduledBy: 
     class: employee 
     local: scheduled_by 
     foreign: id 
    InCharge: 
     class: employee 
     local: in_charge 
     foreign: id 
    soOrder: 
     local: so_id 
     foreign: id 
    Employees: 
     class: employee 
     refClass: schedule_employee 
     local: schedule_id 
     foreign: employee_id 
priority: 
    actAs: 
    SoftDelete: 
    columns: 
    id: 
     primary: true 
     type: integer 
     notnull: true 
     autoincrement: true 
    name: 
     unique: true 
     type: string(255) 
     notnull: true 
    img: 
     type: string(255) 

這些是我正在使用的主表,我正在按計劃嘗試更新優先級

+0

首先你不應該在processForm()中做它,因爲當form被保存時,對象的值將被表單的值覆蓋(在sfForm :: doSave方法中)。你應該在yourModelForm :: doSave或yourModel :: save中做到這一點 – Dziamid 2011-04-07 20:41:20

+0

你能舉一些例子嗎? – Marcelo 2011-04-08 11:04:35

+0

發佈您的架構 – Dziamid 2011-04-08 11:37:23

回答

0

因此,您的任務是在保存之前手動設置與'Schedule'對象的'優先級'關係。

// PriorityForm 
class ScheduleForm extends BaseScheduleForm 
{ 
    public function doSave($con = null) 
    { 
    //update object with form values (not necessary in your case, but will be if you need to 
    //use values that were in form 
    $this->updateObject(); 

    $priority = Doctrine::getTable('Priority')->findOneById(1); 
    $this->getObject()->setPriority($priority); 

    return parent::doSave($con); 
    } 
} 
相關問題