0

I have three tables:

Tag (entity) > tags_articles (pivot) < articles (entity)

Entity "article" has method "addTag(tag)"

If I need to add tags to article I do foreach loop:

foreach ($tags as $tag) {
    $article->add($tag)
}

$this->em->flush()

Sometimes in that loop I need to add over 5000 tags. So all that script takes quite long, around 25s.

Is there any way to speed up that inserts to pivot table?

Thank you.

Mikhail Prosalov
  • 4,155
  • 4
  • 29
  • 41
Klick
  • 1,418
  • 1
  • 23
  • 45
  • 1
    Please see this [link](https://stackoverflow.com/questions/18654530/doctrine2-multiple-insert-in-one-shot) – Kolovos Konstantinos Dec 11 '20 at 15:11
  • @KostasKolovos I know how to do multiple insert new objects. But I ask about inserts in to pivot table. Where we don't have pivot entity. – Klick Dec 11 '20 at 17:07

0 Answers0