开发者

Couldn't call Doctrine_Core::set(), second argument should be an instance of Doctrine_Record or Doctrine_Null when setting one-to-one references

I'm trying to update a foreign key in processForm() and get this error. It's a valid value I can set values to a normal field without problem, I only get this error when I try to update foreign keys

This way i get the error:

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

This way i get no error but doesn't work too:

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

Schema:

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
    InChar开发者_StackOverflow中文版ge:
      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)

These are the main tables i'm using, I'm in schedule and trying to update priority


So, your task is to manually set a 'Priority' relation to a 'Schedule' object before saving it.

// 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);
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜