I have entities Channel and Post. Channel has simple integer id. Post has composite key made of its own id and channel_id.
I would like to have many-to-many relationship between those entities(mention), so that one Post might have many mentioned Channels and Channel might be mentioned by many Posts.
The question is - if it is supported by Doctrine, how do I implement such relationship?
Domain\Telegram\Models\Channel:
type: entity
id:
id:
type: integer
fields:
name:
type: string
nullable: true
oneToMany:
posts:
targetEntity: Domain\Telegram\Models\Post
mappedBy: channel
Domain\Telegram\Models\Post:
type: entity
id:
channel:
associationKey: true
id:
type: integer
manyToOne:
channel:
targetEntity: Domain\Telegram\Models\Channel
inversedBy: posts
Update and solution
Solution by @WilliamPerron almost worked. If used in its current state, doctrine:schema:validate returns an error :
[Mapping] FAIL - The entity-class 'Domain\Telegram\Models\Channel' mapping is invalid:
The inverse join columns of the many-to-many table 'mentions' have to contain to ALL identifier columns of the target entity 'Domain\Telegram\Models\Post', however 'channel_id' are missing.
inverseJoinColumns section should look like this:
inverseJoinColumns:
post_id:
referencedColumnName: id
post_channel_id:
referencedColumnName: channel_id
So this kind of relationship is practically same as simple many-to-many relationship.