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();
注釈を使用してこれを行う方法などの詳細については、「Doctrineドキュメントのセクション5アソシエーションマッピング」のサブセクション5.1.4多対多双方向を参照してください。