diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 8968c99..c4ad051 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -98,8 +98,8 @@ class DefaultController extends AbstractController { $data = json_decode( $data, true ); // die( $data ); $em = $this->getDoctrine()->getRepository( Owner::class ); - $foundOwner = $em->findByEmail( $data[ 'owner' ][ 'email' ] ); - die( $foundOwner ); + $foundOwner = $em->findOneBy( [ 'email' => $data[ 'owner' ][ 'email' ] ] ); + $userWasFound = false; if ( ! $foundOwner ) { //create a new owner @@ -109,12 +109,15 @@ class DefaultController extends AbstractController { $owner->setEmail( $data[ 'owner' ][ 'email' ] ); $foundOwner = $owner; } else { +// die( $foundOwner->getPseudo() ); $userWasFound = true; } // link the owner and the poll $newpoll->setOwner( $foundOwner ); $foundOwner->addPoll( $newpoll ); + $em = $this->getDoctrine()->getManager(); $em->persist( $newpoll ); + $em->persist( $foundOwner ); $em->flush(); $precision = ''; if ( $userWasFound ) {