Skip to content

Unidirectional ManyToMany : rename "id" field #10004

Discussion options

You must be logged in to vote

TLDR Answer : #[InverseJoinColumn(referencedColumnName: 'slug')]


Well, after spending the last afternoon on this question, I didn't expect to find an answer this quickly. An error message suggested that Doctrine makes a clear distinction between fields (which map to columns) and relations (which don't necessarily have a column, at least not on the same table). So I actually defined a dummy field to act as my reverse relation on the Tag end. It looks like this :

    #[ORM\ManyToMany(targetEntity: Question::class, mappedBy: 'tags')]
    #[ORM\JoinColumn(referencedColumnName: 'slug')]
    private $questions;

Then, I stumbled upon this StacOverflow answer with a promising piece of code :

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by edgarogh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant