我正在使用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
你知道在哪里可以找到这个问题的教程/解决方案吗?
非常感谢
答案 0 :(得分: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