Symfony 嵌入表单 - 多对多关系
我使用 symfony 1.4 和 Propel 作为 ORM。我有一个表单需要在其中嵌入其他表单。另一种形式是连接客户和某个对象的 n:m 关系。我不知道如何嵌入它以便它为客户显示所有对象。
考虑以下架构,我想在 Customer 表单中嵌入 CustomerCountryGroup 表单,以显示与用户相关的 CuountryGroup 对象列表。
这是我的 schema.yml:
Customer:
_attributes: { phpName: Customer }
id:
phpName: Id
type: INTEGER
size: '11'
primaryKey: true
autoIncrement: true
required: true
CustomerCountryGroup:
_attributes: { phpName: CustomerCountryGroup }
id:
phpName: Id
type: INTEGER
size: '10'
primaryKey: true
autoIncrement: true
required: true
customerId:
phpName: CustomerId
type: INTEGER
size: '10'
required: false
foreignTable: Customers
foreignReference: id
onDelete: CASCADE
onUpdate: RESTRICT
countryGroupId:
phpName: CountryGroupId
type: INTEGER
size: '10'
required: false
foreignTable: CountryGroups
foreignReference: id
onDelete: CASCADE
onUpdate: RESTRICT
CountryGroup:
_attributes: { phpName: CountryGroup }
id:
phpName: Id
type: INTEGER
size: '11'
primaryKey: true
autoIncrement: true
required: true
你知道我在哪里可以找到这个问题的一些教程/解决方案吗?
非常感谢
I'm using symfony 1.4 and Propel as ORM. I have a form that needs to embed some other form in it. The other form is n:m relation that connects customer and some object. I can't find out how to embed it so that it displays all the objects for a customer.
Considering the following schema, I want to embed CustomerCountryGroup form in Customer form to display a list of CuountryGroup objects related to a user.
Here is my schema.yml:
Customer:
_attributes: { phpName: Customer }
id:
phpName: Id
type: INTEGER
size: '11'
primaryKey: true
autoIncrement: true
required: true
CustomerCountryGroup:
_attributes: { phpName: CustomerCountryGroup }
id:
phpName: Id
type: INTEGER
size: '10'
primaryKey: true
autoIncrement: true
required: true
customerId:
phpName: CustomerId
type: INTEGER
size: '10'
required: false
foreignTable: Customers
foreignReference: id
onDelete: CASCADE
onUpdate: RESTRICT
countryGroupId:
phpName: CountryGroupId
type: INTEGER
size: '10'
required: false
foreignTable: CountryGroups
foreignReference: id
onDelete: CASCADE
onUpdate: RESTRICT
CountryGroup:
_attributes: { phpName: CountryGroup }
id:
phpName: Id
type: INTEGER
size: '11'
primaryKey: true
autoIncrement: true
required: true
Do you know where I can find some tutorial/solution of this problem?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Symfony 应该为你生成多个选择,如果这就是你所说的嵌入的意思。这与实际能够从客户编辑国家/地区相反。我相信你需要将参考表中的 ID 设置为 PK,然后 symfony 就会做它的事情:
Symfony should generate multiple selects for you, if that's what you mean by embedded. This, as opposed to actually being able to edit Countries from a Customer. I believe you need to set the IDs in the reference table as PKs, then symfony will do its thing: