无法使用 SQL Server、Propel15 在 symfony 1.4.8 中保存嵌入表单

发布于 2024-10-17 21:48:53 字数 1290 浏览 1 评论 0原文

我的事件与事件日期之间存在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ花落谁相伴 2024-10-24 21:48:53

我终于明白了。用于设置此块中的值的数组键

公共函数 updateDefaultsFromObject()
{
父级::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);

我们错了。他们应该使用实际的列名称而不是变量的 PHP 名称。所以我不得不

'EventID' => $this->object->getPrimaryKey(),
'EventDateID' => $obj->getEventDateId(),

改为

'eventID' => $this->object->getPrimaryKey(),
'eventdateID' => $obj->getEventDateId(),

I figured it out, finally. The array keys for setting the values in this block

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);

Were wrong. They are supposed to use the actual column names and not the PHP names of the variables. So I had to change

'EventID' => $this->object->getPrimaryKey(),
'EventDateID' => $obj->getEventDateId(),

to

'eventID' => $this->object->getPrimaryKey(),
'eventdateID' => $obj->getEventDateId(),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文