我有一個多對多的關係與鏈接表。請參閱下面的(簡化)架構。 根據教程創建(http://www.symfony-project.org/doctrine/1_2/en/05-Data-Fixtures#chapter_05_many_to_many)symfony多對多的關係循環屬性,而不是對象
架構導入/構建正確和phpmyadmin顯示外鍵正確。 我的印象是,事後在「locatie」模塊的indexSuccess模板我可以打電話:
foreach($locatie->getProducts() as $oProduct):
echo $oProduct->naam;
endforeach;
但是,這並不工作,因爲$ oProduct犯規似乎是一個對象,但表示在每個屬性的字符串產品類。 foreach只是簡單地循環第一個產品的屬性而不是產品列表。 有人有什麼建議嗎?
架構
Locatie:
connection: doctrine
tableName: locatie
columns:
locatie_id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
naam:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
LocatieProduct:
connection: doctrine
tableName: locatie_product
columns:
locatie_product_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
locatie_id:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: true
autoincrement: false
product_id:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: true
autoincrement: false
relations:
Locatie:
local: locatie_id
foreign: locatie_id
foreignAlias: LocatieProducts
onDelete: CASCADE
Product:
local: product_id
foreign: product_id
foreignAlias: LocatieProducts
onDelete: CASCADE
Product:
connection: doctrine
tableName: product
columns:
product_id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
naam:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
這解決了這個問題,我錯過了很多和refClass。我對這個整個原則有些新東西,但我的想法是對的,我應該能夠直接從我的本地模型中檢索產品。謝謝傑里米! – tomvo 2010-12-18 09:37:26