外键永不保存嵌入关系
问题描述:
我花了好几个小时才找到解决方案,将外键保存在母表中。 我想用symfony 1.4的嵌入关系(我也有ahDoctrineEasyEmbeddedRelationsPlugin)。外键永不保存嵌入关系
当我读到这里symfony的文档
http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms
的模式是:
Product:
columns:
name: { type: string(255), notnull: true }
price: { type: decimal, notnull: true }
ProductPhoto:
columns:
product_id: { type: integer }
filename: { type: string(255) }
caption: { type: string(255), notnull: true }
relations:
Product:
alias: Product
foreignType: many
foreignAlias: Photos
onDelete: cascade
的embedRelation样子:
// lib/form/doctrine/ProductForm.class.php
public function configure()
{
// ...
$this->embedRelation('Photos');
}
在我来说,我不能另一方面,这是相反的,产品有关系键,ih AVE类似的东西:
Product:
columns:
name: { type: string(255), notnull: true }
price: { type: decimal, notnull: true }
photoid: { type: integer }
ownerid: { type: integer }
relations:
Photo:
local: photoid
foreign: id
type: one
Owner:
local: ownerid
foreign: id
type: one
Photo:
columns:
id : { type: integer }
filename: { type: string(255) }
caption: { type: string(255), notnull: true }
owner:
columns:
id : { type: integer }
firstname: { type: string(255) }
lastname: { type: string(255), notnull: true }
和embedRelation:
// lib/form/doctrine/ProductForm.class.php
public function configure()
{
// ...
$this->embedRelation('Photo');
$this->embedRelation('Owner');
}
还有不小部件有关,如姓名或价格的产品形式更新,但只有信息从照片和主表来。
当我保存新表格时,照片和所有者对象保存在表格中,并且ID是使用序列创建的。问题是产品从不更新。 photoid和ownerid仍然保持为空。 这就像嵌入式表单照片和所有者保存在根表单之后。
在这种情况下可以使用嵌入吗? 如果那么当根表单保存在processForm中时,在Product表中保存外键的正确方法是什么? 有什么窍门,thx求助。
usefields是显示为文件说:“sfForm :: useFields()是一种新功能,Symfony的1.3是允许开发人员准确指定表单应该使用哪些字段以及应该按什么顺序显示,其他所有非隐藏字段都将从表单中删除。“两个表的ID隐藏在表单中。我遇到的问题是保存外键,而不是显示。 – philcaba 2012-02-13 10:08:03