无法使用 SQL Server、Propel15 在 symfony 1.4.8 中保存嵌入表单
我的事件与事件日期之间存在 1:M 关系。在 EventForm 类中,我按如下方式嵌入 EventDate 表单:
$this->embedRelation('EventDate', array('title' => 'dates', 'empty_label' => 'New'));
并按如下方式填充编辑表单上的初始数据:
public function updateDefaultsFromObject()
{
parent::updateDefaultsFromObject();
$i = 1;
$values = array();
foreach ($this->object->getEventDates() as $obj)
{
$values[$i] = array(
'EventID' => $this->object->getPrimaryKey(),
'EventDateID' => $obj->getEventDateId(),
'startDateTime' => $obj->getStartDateTime(),
'endDateTime' => $obj->getEndDateTime());
$i++;
}
$this->setDefault('dates', $values);
}
问题是当它尝试保存时我得到:
Unable to execute UPDATE statement [UPDATE EventDates SET EVENTDATEID=:p1
WHERE EventDates.EVENTDATEID IS NULL ] [wrapped: SQLSTATE[HY000]: General
error: 8102 General SQL Server error: Check messages from the SQL Server
[8102] (severity 16) [(null)]]
MSSql 错误 8102 是它正在尝试更新标识列,这是 EVENTDATEID。我不知道为什么要这样做。另外,根据更新语句判断,我有一种感觉, $this->object->getEventDates() 中有一个空对象正在尝试更新。如果我能以某种方式解决这个问题,我假设(参见:祈祷)它将解决这个错误。
I have a 1:M relationship of Events with Event Dates. In the EventForm class, I am embedding the EventDate forms as so:
$this->embedRelation('EventDate', array('title' => 'dates', 'empty_label' => 'New'));
and filling the initial data on the edit forms as so:
public function updateDefaultsFromObject()
{
parent::updateDefaultsFromObject();
$i = 1;
$values = array();
foreach ($this->object->getEventDates() as $obj)
{
$values[$i] = array(
'EventID' => $this->object->getPrimaryKey(),
'EventDateID' => $obj->getEventDateId(),
'startDateTime' => $obj->getStartDateTime(),
'endDateTime' => $obj->getEndDateTime());
$i++;
}
$this->setDefault('dates', $values);
}
The problem is when it tries to save I get:
Unable to execute UPDATE statement [UPDATE EventDates SET EVENTDATEID=:p1
WHERE EventDates.EVENTDATEID IS NULL ] [wrapped: SQLSTATE[HY000]: General
error: 8102 General SQL Server error: Check messages from the SQL Server
[8102] (severity 16) [(null)]]
MSSql error 8102 is that it is trying to update an identity column, which is EVENTDATEID. I have no idea why it's doing this. Also, it I have a feeling, judging by the update statement, that there is an empty object in $this->object->getEventDates() that it is trying to update. If I could fix that somehow, I assume (see: pray) that it will fix this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于明白了。用于设置此块中的值的数组键
公共函数 updateDefaultsFromObject()
{
父级::updateDefaultsFromObject();
我们错了。他们应该使用实际的列名称而不是变量的 PHP 名称。所以我不得不
改为
I figured it out, finally. The array keys for setting the values in this block
public function updateDefaultsFromObject()
{
parent::updateDefaultsFromObject();
Were wrong. They are supposed to use the actual column names and not the PHP names of the variables. So I had to change
to