I'm looking for a suggestion on how to map a OneToMany/ManyToOne relationship that uses a join table. The mapping I have is not taking, and I get an error that article_id is not set in the media table.
class Media
{
// ...
/**
* @ManyToOne(targetEntity="Document", inversedBy="media")
* @JoinTable(name="articles_x_media", referencedColumnName="id")
* joinColumns={@JoinColumn(name="media_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="bid_id", referencedColumnName="id")})
* )
*/
protected $document;
}
class Document
{
// ...
/**
* @OneToMany(targetEntity="Media", mappedBy="document"))
* @JoinTable(name="articles_x_media", referencedColumnName="id")
* joinColumns={@JoinColumn(name="article_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="media_id", referencedColumnName="id")}
* )
*/
protected $media;
}
There's a specific paragraph in the documentation about OneToMany
mapping with join table.
Anyway, what you probably want is an uni-directional ManyToMany
association.
Also, @OneToMany
does not come with a @JoinTable
, and the same for @ManyToOne
either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With