开发者

Can not save embedded form in symfony 1.4.8 with SQL Server, Propel15

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开发者_JS百科 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.


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(),
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜