Symfony 嵌入表单 - 多对多关系

发布于 2024-10-17 17:32:22 字数 1213 浏览 8 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追风人 2024-10-24 17:32:22

Symfony 应该为你生成多个选择,如果这就是你所说的嵌入的意思。这与实际能够从客户编辑国家/地区相反。我相信你需要将参考表中的 ID 设置为 PK,然后 symfony 就会做它的事情:

CustomerCountryGroup:
  _attributes: { phpName: CustomerCountryGroup }
  customerId:
    phpName: CustomerId
    type: INTEGER
    required: true
    primaryKey: true
    foreignTable: Customers
    foreignReference: id
    onDelete: CASCADE
    onUpdate: CASCADE
  countryGroupId:
    phpName: CountryGroupId
    type: INTEGER
    required: true
    primaryKey: true
    foreignTable: CountryGroups
    foreignReference: id
    onDelete: CASCADE
    onUpdate: CASCADE

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:

CustomerCountryGroup:
  _attributes: { phpName: CustomerCountryGroup }
  customerId:
    phpName: CustomerId
    type: INTEGER
    required: true
    primaryKey: true
    foreignTable: Customers
    foreignReference: id
    onDelete: CASCADE
    onUpdate: CASCADE
  countryGroupId:
    phpName: CountryGroupId
    type: INTEGER
    required: true
    primaryKey: true
    foreignTable: CountryGroups
    foreignReference: id
    onDelete: CASCADE
    onUpdate: CASCADE
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文