2017-03-09 4 views
0

symfony2アプリケーションで2つのクラス間の関係を作成しました。このように、tableBはtableAに関連するように設計されました。私はtableAテーブル(スーパーエンティティとして)にデータを入力しました。私のコントローラでは、jsonを使用してtableBテーブルにデータを挿入するポストを作成しています。これは私が私で郵便配達500内部サーバーエラー - 渡された引数はクラス型でなければなりませんが、整数が与えられます - symfony2

{ 
"id": 6, 
"variable": false, 
"variable": true, 
"variable": true, 
"variable": true, 
"variable": false, 
"variable": true, 
"variable": true, 
"variable": true, 
"variable": false, 
"variable": false, 
"variable": true, 
"fkValue":3 //area of challenge 
} 

から投稿しています私のJSON形式で

{ 
"message": "Expected value of type "\myBundle\Entity\TableA" for association field "\myBundle\Entity\Platforms#$dataValue", got "integer" instead.", 
"class": "Doctrine\ORM\ORMInvalidArgumentException", 

TABLEBから参照する外部キーは整数を取るが、私は郵便配達からのポストを作成しようとすると、私はこの奇妙なエラーが出ますエンティティクラスIは、このコードスニペットEDITED

/** 
    * 
    * 
    * @param \MyBundle\Entity\TableA $dataValue 
    * @return Platforms 
    */ 
    public function setValue(\Api3Bundle\Entity\TableA $dataValue = null) 
    { 
     $this->dataValue = $dataValue ; 

     return $this; 
    } 

================ ==================を持っています

これは私が正しい軌道に乗っていますが、いくつかのデータを挿入する方法私を見ることができれば知らない私はTableAの

//getting the value from request 
$variable = $request->get('variable'); 

//setting the value for persistence 
$data->setValue($variable);//area of challenge 
    $em = $this->getDoctrine()->getManager(); 
$em = $this->getDoctrine()->getManager(); 
    $em->persist($data); 

の外部キーフィールドにTableBのにコントローラからのデータを挿入しています方法です郵便配達員からのjsonを使用する外部キーフィールド。多くのおかげで

+0

送信されています?あなたのsetValueには、jsonではなくTableAエンティティが必要です。 –

+0

@Andrew Nolanちょっとお答えしましたが、回答やご提案を – parker

+0

に投稿していただければ、 'variable'がTableAのインスタンスではない場合は、500エラーが発生します。メソッドを変更してパラメータとして整数を受け入れるか、TableAエンティティをインスタンス化して 'setValue()'メソッドに渡します。 –

答えて

0

あなただけのキーを送信しているので、あなたが使用することができます。

$data->setValue($this->entityManager->getReference('EntityName', $request->get('fkValue')));//area of challenge 

出典:あなたのJSONは、 `\ Api3Bundle \エンティティ\ TableA`インスタンスに変換されているAPIにhttp://doctrine-orm.readthedocs.io/en/latest/reference/unitofwork.html

関連する問題