2017-07-14 14 views
0

私はDoctrine 2とSymfony 2.7を使用しています。私のローカルマシンでうまくいきましたが、実際にはそれは奇妙な問題に遭遇しました。PHP Doctrine - 2つのテーブルを順にフラッシュするのに失敗しました

新しいUserエンティティを作成し、そのユーザーの新しいUserProfileエンティティを作成するPHPスクリプトがあります。しかし、いつかUserProfileが作成され、時にはそうではありません。スクリプトの残りの部分も停止されています。 「$ EM->フラッシュ();」ここ

は私のコード

$user = new Entity\User(); 
$user->setEmail(trim($data['email'])); 
$user->setName(trim($data['email'])); 
$user->setSalt($userManager->generateSalt()); 
$user->setPassword($data['encrypted_password']); 
$em->persist($user); 
$em->flush(); 

$profile = new Entity\UserProfile(); 
$profile->setIdUser($user->getId()); 
$profile->setIdDomain($themeHelper->getIdDomain()); 
$profile->setIsActive(true); 
$profile->setIdAccountType($data['idAccountType']); 
$em->persist($profile); 
$em->flush(); 

は、私は待つ必要が万が一があるのですユーザーが完了するまで、残りの部分を実行し続けますか?

多くのありがとうございます。

+0

どのエラーが表示されますか? –

+1

これは関連するかもしれませんが、これは必要ではないでしょう。 '$ profile-> setIdUser($ user-> getId());'、 'setUser($ user)'というメソッドがあります。そして、両方のエンティティを永続化した後で、 ' - > flush'を一度呼び出すことができるはずです。そして、doctrineはマッピングと正しい挿入順序を処理します。 – Flosculus

+0

私は何のエラーもありません。ほとんどの場合、これはエンドユーザーがサインアップするときに発生します。私はログファイルでエラーを探すことを試みたが、運がない、また私はそれが再び自分自身で起こるように試みたが、それは正常に動作していた。 – pthphap

答えて

0
Try once : 
After flushing the $user object first check the user record has been set properly and after checking it in 'if' condition like: 
if($user-> get Id()) 
{ 
$profile = new Entity\UserProfile(); 
$profile->setIdUser($user->getId()); 
$profile->setIdDomain($themeHelper->getIdDomain()); 
$profile->setIsActive(true); 
$profile->setIdAccountType($data['idAccountType']); 
$em->persist($profile); 
$em->flush(); 
} 
may be this will work and if not you would be able to know where it is creating problem 
関連する問題