Доктрина версия 2.1доктрина 2,1 - объект не может быть сохранен
я сохраняющиеся много объектов, поэтому я должен сделать $this->entityManager->clear()
после $this->entityManager->flush()
, однако это вызывает хорошо известную ошибку:
Exception: "A new entity was found through the relationship 'Entities\A#B' that was not configured to cascade persist operations for entity: Entities\[email protected] Explicitly persist the new entity or configure cascading persist operations on the relationship. If you cannot find out which entity causes the problem implement 'Entities\B#__toString()' to get a clue."
Он работает для первого флеша, но он не работает для всех остальных. Когда я комментирую $this->entityManager->clear();
Вот пример кода:
if ($flushCounter % 50 == 0) {
$this->entityManager->flush();
$this->entityManager->clear();
//$this->entityManager->detach($B); <- with these two lines commented I tried to fix the error, but it did not work
//$B = $this->entityManager->find(ENTITY_NAMESPACE . "\B", (int) $B_id);
}
$flushCounter++;
Повторюсь, что комментирование ясно() функция устраняет проблему, но я не хочу этого делать, если не лучший способ управления память
Кажется, что вы меняете объекты, которые находятся в ассоциациях, но на обратной стороне ассоциации. Поэтому, когда вы пытаетесь сохранить свою сторону, поскольку нет набора 'CASCADE: persist', он выдает ошибку. –