symfony 1.4 embedForm 保存2次问题

When a form is embedded, the embedded model representation is saved twice: one via fromArray(), that automatically hydrates related components, and another time via saveEmbeddedForm.

使用embed会出现insert 2次的问题

configure(){
embedRelation('ForwardProfile');
}
function addProfile(){
//embed a new form
$profiles = new sfForm();
      $profile = new ForwardProfile();
      $profile->setForward($this->getObject());
      $profile_form = new ForwardProfileForm($profile);
      $profiles->embedForm('0',$profile_form);
      $this->embedForm('ForwardProfile',$profiles);
}
function bind(){
$this->addProfile();
}

这时会出现插入2条记录的情况,将关联名称‘ForwardProfile改为其它名字可以解决

....
function addProfile(){
//embed a new form
...
      $this->embedForm('Fp',$profiles);
}
....
This entry was posted in forms. Bookmark the permalink.

Comments are closed.