I just don开发者_如何学运维't really get this part
Say you clear a collection of tags by calling $post->getTags()->clear(); and then call $post->getTags()->add($tag). This will not recognize tag being already added before and issue two database calls.
What 2 database calls will be issued? Delete all tags of the post then add one? Thats what I'd expect? Or will it be something else?
Did you try to call after the clear?
$entityManager->flush();
If this don't help try to remove one by one in foreach.
精彩评论