如果您正在使用YML定义你的实体:
在Piercing.orm.yml补充:
manyToMany:
caretakings:
targetEntity: Caretaking
inversedBy: piercings
joinTable:
name: piercing_caretaking
joinColumns:
caretaking:
referencedColumnName: id
inverseJoinColumns:
piercing:
referencedColumnName: id
在Caretaking.orm.yml补充:
manyToMany:
piercings:
targetEntity: Piercing
mappedBy: caretakings
生成/更新通常方式的实体,即:
app/console doctrine:schema:update --dump-sql (to check results)
app/console doctrine:schema:update --force (to apply changes)
然后,当你有一个穿孔或看管实体可以访问相关的实体是这样的:
$piercing->addCaretaking($caretaking);
$caretakings = $piercing->getCaretakings();
...
$piercings = $caretaking->getPiercings();
欲了解更多信息,包括如何做到这一点使用说明,请参见小节5.1.4多对多, Doctrine文档的Section 5 Association Mapping双向。
感谢您的回答,它只是清除了我遇到的致命异常和不存在的功能问题。尽管我使用注释而不是YAML,但很容易调整您的解决方案。 – nealio82 2012-06-19 19:51:16