1

我正在使用 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

你知道我在哪里可以找到这个问题的一些教程/解决方案吗?

非常感谢

4

1 回答 1

2

如果这就是嵌入式的意思,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
于 2011-02-15T21:48:43.383 回答