保存嵌入式 Propel symfony 表单以实现一对一关系
我有一对具有一对一关系的表。
我有一个投诉表单,需要在其中嵌入一个人员表单,相关架构如下:
complaint:
id: ~
created_at: ~
updated_at: ~
complainant_id: { type: integer, foreignTable: person_data, foreignReference: id, onDelete: setnull }
status: { type: tinyint, default: 1 }
complaint_title: { type: varchar(64) }
complaint_number: { type: varchar(16) }
recipient: { type: varchar(128) }
person_data:
id: ~
created_at: ~
updated_at: ~
company_name: { type: varchar(64) }
first_name: { type: varchar(64) }
last_name: { type: varchar(64) }
email: { type: varchar(128) }
我能够成功地将两个对象保存到数据库,但主要投诉对象没有使用 person_data 行的投诉 ID 进行更新。
有谁知道为什么这不能正常工作以及如何强制它正确更新投诉对象?
我使用的是 symfony 1.4.13,Propel 1.6.3。
更新:
以下是嵌入表单的代码:
<?php
public function configure()
{
$use_fields = array();
// ...other fields added...
$sub_form = new PersonDataForm(array(), array());
$this->embedForm('complainant', $sub_form);
array_push($use_fields, 'complainant');
$this->useFields($use_fields);
}
I have a pair of tables that have a one-to-one relationship.
I have a complaint form that needs to embed a person form inside of that, the relevant schema is below:
complaint:
id: ~
created_at: ~
updated_at: ~
complainant_id: { type: integer, foreignTable: person_data, foreignReference: id, onDelete: setnull }
status: { type: tinyint, default: 1 }
complaint_title: { type: varchar(64) }
complaint_number: { type: varchar(16) }
recipient: { type: varchar(128) }
person_data:
id: ~
created_at: ~
updated_at: ~
company_name: { type: varchar(64) }
first_name: { type: varchar(64) }
last_name: { type: varchar(64) }
email: { type: varchar(128) }
I am able to successfully save both objects to the database but the main complaint object is not being updated with the complainant_id of the person_data row.
Does anyone know why this isn't working correctly and how to force it to update the complaint object correctly?
I am using symfony 1.4.13, Propel 1.6.3.
UPDATE:
Here is the code for the embedded form:
<?php
public function configure()
{
$use_fields = array();
// ...other fields added...
$sub_form = new PersonDataForm(array(), array());
$this->embedForm('complainant', $sub_form);
array_push($use_fields, 'complainant');
$this->useFields($use_fields);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决这个问题的办法。
重写表单类中的 saveEmbeddedForms 方法。
更新主对象发生在保存嵌入表单之后,因此 ids 可用于更新主对象。
不幸的是,我在互联网上找不到任何有此解释的地方。这是为那些追随我的人准备的。
I've found a solution to this problem.
Override the saveEmbeddedForms method in the form class.
Updating the main object occurs after the saving of the embedded forms so the ids are available to update the main object.
Unfortunately there is nowhere that I can find on the internet with this explanation. So here it is for those that come after me.