Symfony, 无效数据 (AppBundle\Entity\InterventionType), 预期 "AppBundle\Entity\Intervention



我正在尝试在我的基中插入一行,从邮递员到带有一些外键的本地 api,我有这个错误:

"message": "无效数据 \"1\"(AppBundle\Entity\InterventionType(, 预期的"AppBundle\Entity\Intervention\"。

它指向了坏实体,我不知道为什么。我的目标是"干预",而学说似乎在干预类型中...... 这是我的实体:

<?php
namespace AppBundleEntity;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use DateTime;
/**
* InterventionRapport
*
* @ORMTable(name="intervention_rapport", options={"comment":"Table répertoriant les retours associés aux différentes interventions (commerciales et techniques) - Egalement utilisée pour rémunérer les techniciens et calculer les frais kilométriques tech/com"})
* @ORMEntity
*/
class InterventionRapport
{
/**
* @var integer
* @ORMOneToOne(targetEntity="AppBundleEntityIntervention")
* @ORMJoinColumn(name="intervention", nullable=false)
*/
private $intervention;
/**
* @var string
*
* @ORMColumn(name="message", type="text", nullable=true)
*/
private $message;
/**
* @var integer
*
* @ORMColumn(name="statut", type="integer", nullable=false)
*/
private $statut = '0';
/**
* some other things
**/
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;

}

以及外键目标实体:

<?php
namespace AppBundleEntity;
use DoctrineORMMapping as ORM;
/**
* Intervention
*
* @ORMTable(name="intervention")
* @ORMEntity
*/
class Intervention
{
/**
* @var integer
*
* @ORMManyToOne(targetEntity="AppBundleEntityInterventionType")
* @ORMJoinColumn(name="type", nullable=false)
*/
private $type;
/**
* Some other things
**/
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
}

最后是我的json:

{
"message": "Steuh plait !",
"statut": 1,
"datemaintenanceprevue": "2017-08-23T15:00:00+00:00",
"heuresintervention": 1,
"heurestrajet": 0.5,
"kmtrajet": 27,
"deleted": 0,
"intervention": 1,
"id": 2
}

请帮忙,我做错了什么?

我通过更改创建线条的方式找到了一条线。我没有直接输入干预 id,而是将其传递到 url 中:

class RapportController extends Controller
{  
/**
* @RestPost(
*    path = "/reports/intervention={id}",
*    name = "app_report_create"
* )
* @RestView(StatusCode = 201)
* @ParamConverter("report", converter="fos_rest.request_body")
*/
public function createAction(Request $request, InterventionRapport $report)
{
$em = $this->getDoctrine()->getManager();
$intervention = $this->get('doctrine.orm.entity_manager')
->getRepository('AppBundle:Intervention')
->find($request->get('id'));
//$report = new DateTime($datemaintenanceprevue);
$report->setIntervention($intervention);
$em->persist($report);
$em->flush();
return $report;
}

因此,我不需要从客户的json发布干预ID:

{
"message": "Steuh plait !",
"statut": 1,
"datemaintenanceprevue": "2017-08-23T15:00:00+00:00",
"heuresintervention": 1,
"heurestrajet": 0.5,
"kmtrajet": 27,
"deleted": 0,
"id": 2

}

我不知道这是否是正确的方法,但它解决了问题。希望它可以帮助别人。

相关内容

  • 没有找到相关文章

最新更新