这是我的问题:我想创建一个“资源”的新实例,并直接创建与该资源相关的'ResourceDescriptions'实例,并将1:n关系转换为一种形式。
一些背景信息:
1)简化架构
ResourceDescriptions:
connection: doctrine
tableName: resource_descriptions
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
description:
type: string()
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Resources:
local: id
foreign: id
type: one
Resources:
connection: doctrine
tableName: resources
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
relations:
ResourceDescriptions:
local: id
foreign: id
type: many
2)ResourcesForm
if ($this->getObject()->isNew()){
$newDescription = new ResourceDescriptions();
$newDescription->setResources($this->getObject());
$newDescription->setId($this->getObject()->getId());
$newDescriptionForm = new ResourceDescriptionsForm($newDescription);
$this->embedForm('Description', $newDescriptionForm);
}
$this->embedRelation('ResourceDescriptions');
3)ResourceDescriptionsForm
public function configure(){
$this->useFields(array('id', 'description'));
$this->setWidgets(array('id' => new sfWidgetFormInputHidden(array('default' => $this->getObject()->getId())), 'description' => new sfWidgetFormTextarea(),'expanded' => true,'multiple' => true),array('class' => 'checkbox'))));
$this->setValidators(array('id' => new sfValidatorPass, 'description' => new sfValidatorString(array('max_length' => 250)), 'multiple' => true))));
}
这里的问题是我想得到一个'资源'对象的id还没有被放入数据库...有没有办法在插入之前得到它或另一种方法是能够同时(或多或少)创建描述作为资源吗?