On my symfony project (5.x version), I have a simple ManyToMany relation between Metas and Tags (no fetch and no cascade defined).
class Meta
{
...
/**
* @ORM\ManyToMany(targetEntity="Tag", mappedBy="meta")
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $tags;
}
class Tag
{
...
/**
* @ORM\ManyToMany(targetEntity="Meta", inversedBy="tags")
* @ORM\JoinTable(name="app_meta_tag")
* @ORM\JoinColumn(name="meta_id")
*/
protected $meta;
}
I can have 40 000 metas having the same tag (for example "test").
When I add the "test" tag to a Meta, then persist and flush, all the Metas related to this tag are flushed ... and return a 500 error because of memory limit. This behaviour seems to be in contradiction with doctrine doc : https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/working-with-associations.html#persistence-by-reachability-cascade-persist
Can someone have an explanation about this ? Thanks !
As we have an elasticsearch database allowing us to get all metas for a tag, I finally I found a woking solution : making the relation unidirectional.