我有一个多对多的关系与链接表。请参阅下面的(简化)架构。 根据教程创建(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