2011-02-13 93 views
1

我使用symfony 1.4和Propel作为ORM。我有一个需要在其中嵌入其他表单的表单。另一种形式是连接客户和某个对象的n:m关系。我找不到如何嵌入它,以便显示客户的所有对象。Symfony嵌入式表格 - 多对多关系

考虑到以下模式,我想在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 

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

非常感谢

回答

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