The good way to persist a FOSUser entity in cascade

前提是你 提交于 2019-12-03 21:12:38

When you're creating an instance of Structure and then trying to persist/flush... Doctrine2 is:

  1. Realising that there is a relationship on Structure with User (each Stucture instance must have a User instance)
  2. Because there is no User explicitly bound to the Structure instance, it tries to create an empty one.
  3. The save operation on the User fails, because there is no data (in this case, usernameCanonical string is empty)

What you must do is...

Before you save the Structure, add an instance of User to it... if you want to use the current user then use this

$user = $this->get('security.context')->getToken()->getUser();
$structure->setMaster($user);
$em->persist($structure);
$em->flush();

Remember to include the User entity in your controller class (with the use statement).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!