2011-02-13 89 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