Symfony1 一对多和保存记录
我正在创建一个简单的CMS,我有一套模板,每个模板可以有多个块在其中 所以我在模板和块之间有一对多的关系(一个模板可以有多个块) 因此,当我创建一个块时,它有一个模板下拉列表,我可以使用Symfony1 一对多和保存记录,symfony1,symfony-1.4,Symfony1,Symfony 1.4,我正在创建一个简单的CMS,我有一套模板,每个模板可以有多个块在其中 所以我在模板和块之间有一对多的关系(一个模板可以有多个块) 因此,当我创建一个块时,它有一个模板下拉列表,我可以使用sfDoctrineChoice小部件将该块与之关联 在我的BlockForm.class.php中 新的sfWidgetFormDoctrineChoice(数组('model'=>'Template','multiple'=>true',expanded'=>false)) 我的模式是: Template:
sfDoctrineChoice
小部件将该块与之关联
在我的BlockForm.class.php中
新的sfWidgetFormDoctrineChoice(数组('model'=>'Template','multiple'=>true',expanded'=>false))
我的模式是:
Template:
actAs:
Timestampable: ~
columns:
name:
type: varchar(255)
layout:
type: text
relations:
Block:
class: Block
local: id
foreign: template_id
type: many
foreignType: one
alias: Block
foreignAlias: Template
Block:
columns:
template_id: { type: integer(8), notnull: true }
content: { type: clob, notnull: true }
当我试图保存选择时,问题就出现了。它给了我一个:
SQLSTATE[HY093]:无效参数编号:当我选择2个或多个模板或选择1个选项时,绑定变量的数量与令牌的数量不匹配
:
SQLSTATE[23000]:完整性约束冲突:1452无法添加或更新子行:外键约束失败(
db
block,约束
block\u template\u id\u template\u id外键(
template\u id)引用
template(
id)
我的模式是否正确,可以执行我希望执行的操作
谢谢您必须添加外键约束。onDelete和onUpdate
Template:
actAs:
Timestampable: ~
columns:
name:
type: varchar(255)
layout:
type: text
Block:
columns:
template_id: { type: integer(8), notnull: true }
content: { type: clob, notnull: true }
relations:
Template:
local: template_id
foreign: id
foreignAlias: Blocks
这也没用。当我选择一个选项时,我现在得到:
数组到字符串的转换…
这是奇数。当选择2个或更多的模板时,我仍然会得到完整性约束
,这仍然会给我带来上述的intetgrity冲突问题。