Symfony1 不能';t调用Doctrine_Core::set(),设置一对一引用时,第二个参数应为Doctrine_Record或Doctrine_Null的实例
我正在尝试更新processForm()中的外键并获取此错误。 这是一个有效值 我可以毫无问题地将值设置为正常字段,只有在尝试更新外键时才会出现此错误 这样我就得到了错误:Symfony1 不能';t调用Doctrine_Core::set(),设置一对一引用时,第二个参数应为Doctrine_Record或Doctrine_Null的实例,symfony1,doctrine,Symfony1,Doctrine,我正在尝试更新processForm()中的外键并获取此错误。 这是一个有效值 我可以毫无问题地将值设置为正常字段,只有在尝试更新外键时才会出现此错误 这样我就得到了错误: $form->getObject()->setPriority(1); 这样我不会出错,但也不起作用: $form->getObject()->setPriorityId(1); 模式: schedule: columns: id: primary: true
$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)
这些是我正在使用的主表,我正在计划并尝试更新优先级,因此,您的任务是在保存“计划”对象之前手动设置“优先级”关系
// 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);
}
}
首先,不应该在processForm()中执行此操作,因为保存表单时,对象的值将被表单的值覆盖(在sfForm::doSave方法中)。您应该在您的modelform::doSave或您的model::save中执行此操作。您可以展示一些示例吗?