I need help for my problem. When add the relationship ManyToMany to the php script this return when validate the relationship. This is my scripts:
class Post implements ResourceInterface, TranslatableInterface
{
/**
* @var int
*/
private $id;
/**
* @var bool
*/
private $important;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Tag", inversedBy="posts")
* @ORM\JoinTable(name="posts_tags",
* joinColumns={
* @ORM\JoinColumn(name="post_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
* }
* )
*/
private $tags;
}
And
class Tag implements ResourceInterface, TranslatableInterface
{
use TranslatableTrait {
__construct as private initializeTranslationsCollection;
}
/**
* @var int
*/
private $id;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Post",
mappedBy="tags")
*/
private $posts;
}
The error is:
Mapping
[FAIL] The entity-class AppBundle\Entity\Tag mapping is invalid: * The field AppBundle\Entity\Tag#posts is on the inverse side of a bi-
directional relationship, but the specified mappedBy association on the target-entity AppBundle\Entity\Post#tags does not contain the required 'inversedBy="posts"' attribute.
Hello use symfony maker
. /bin/console make:entity Post
For the field name enter 'tags' and for the type enter 'relation' . Then give the related tags entity name. Shoud be Tag. Choose the manytomany relation and enter. Like this you should never have relation issue :-). Even if the entity exist already.
maybe the mapping of the tags attribute in the post entity should be like this:
class Post implements ResourceInterface, TranslatableInterface
{
/**
* @var int
*/
private $id;
/**
* @var bool
*/
private $important;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Tag", inversedBy="posts", cascade={"persist"})
* @ORM\JoinTable(name="posts_tags",
* joinColumns={
* @ORM\JoinColumn(name="post_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
* }
* )
*/
private $tags;
}
I hope I've helped :)