Код: Выделить всё
A new entity was found through the relationship 'App\Entity\ReseauxSociaux\Conversation#utilisateur1' that was not configured to cascade persist operations for entity: John_Doe. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}).
Код: Выделить всё
$conversation = new Conversation();
$conversation->setUtilisateur1($user);
$conversation->setUtilisateur2($otherUser);
$this->entityManager->persist($conversation);
$this->entityManager->flush();
Код: Выделить всё
class Conversation
{
...
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="conversations")
*
*/
private $utilisateur1;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $utilisateur2;
}
Код: Выделить всё
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="conversations", cascade={"persist"})
*
*/
private $utilisateur1;
Код: Выделить всё
"An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'UNIQ_8D93D649E7927C74'"
Подробнее здесь: https://stackoverflow.com/questions/786 ... but-manyto