I get this error:
A new entity was found through the relationship 'AppEntityReseauxSociauxConversation#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"}).
This is in my controller
$conversation = new Conversation();
$conversation->setUtilisateur1($user);
$conversation->setUtilisateur2($otherUser);
$this->entityManager->persist($conversation);
$this->entityManager->flush();
This is in my entity conversation:
class Conversation
{
...
/**
* @ORMManyToOne(targetEntity=User::class, inversedBy="conversations")
*
*/
private $utilisateur1;
/**
* @ORMManyToOne(targetEntity=User::class)
*/
private $utilisateur2;
}
Then I added cascade={"persist"}
to my attribute utilisateur1 like this:
/**
* @ORMManyToOne(targetEntity=User::class, inversedBy="conversations", cascade={"persist"})
*
*/
private $utilisateur1;
Then I get:
"An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'UNIQ_8D93D649E7927C74'"