In the entity products
I am relating my products to my productgroup:
/**
* @ORM\ManyToOne(targetEntity="Productgroup")
* @ORM\JoinColumn(name="productgroup", referencedColumnName="id")
*/
private $productgroup;
This i working well.
So for example this is the result:
Product Productgroup
Frog Animal
Fish Animal
Pizza Food
But sometimes my products have multiple productgroups like this:
Frog Animal
Fish Animal, Food
Pizza Food
So I changed my entity to this:
/**
* @ORM\ManyToMany(targetEntity="Productgroup")
* @ORM\JoinColumn(name="productgroup", referencedColumnName="id")
*/
private $productgroup;
public function getProductgroup(): ?Productgroup
{
return $this->productgroup;
}
public function setProductgroup(?Productgroup $productgroup): self
{
$this->productgroup = $productgroup;
return $this;
}
Now I get the error message:
Return value of App\Entity\Products::getProductgroup() must be an instance of App\Entity\Productgroup or null, instance of Doctrine\ORM\PersistentCollection returned