我试图在我的基地插入一条线,从邮递员到带有一些外键的本地api,我有这个错误:
" message":"无效数据\" 1 \"(AppBundle \ Entity \ InterventionType), 预期\" AppBundle \ Entity \ Intervention \"。"
它指出了不好的实体,我不知道为什么。我瞄准"干预",而且学说似乎是InterventionType ... 这是我的实体:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use \DateTime;
/**
* InterventionRapport
*
* @ORM\Table(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"})
* @ORM\Entity
*/
class InterventionRapport
{
/**
* @var integer
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Intervention")
* @ORM\JoinColumn(name="intervention", nullable=false)
*/
private $intervention;
/**
* @var string
*
* @ORM\Column(name="message", type="text", nullable=true)
*/
private $message;
/**
* @var integer
*
* @ORM\Column(name="statut", type="integer", nullable=false)
*/
private $statut = '0';
/**
* some other things
**/
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
}
&#13;
以及使用外键定位的实体:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Intervention
*
* @ORM\Table(name="intervention")
* @ORM\Entity
*/
class Intervention
{
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\InterventionType")
* @ORM\JoinColumn(name="type", nullable=false)
*/
private $type;
/**
* Some other things
**/
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
}
&#13;
最后我的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
}
请帮助,我做错了什么?
答案 0 :(得分:0)
我通过改变创建线条的方式找到了一种洗脱方法。我没有直接输入干预ID,我将其传递到网址:
class RapportController extends Controller
{
/**
* @Rest\Post(
* path = "/reports/intervention={id}",
* name = "app_report_create"
* )
* @Rest\View(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;
}
&#13;
所以,我不需要从我的客户发布干预ID&#39;杰森:
{
"message": "Steuh plait !",
"statut": 1,
"datemaintenanceprevue": "2017-08-23T15:00:00+00:00",
"heuresintervention": 1,
"heurestrajet": 0.5,
"kmtrajet": 27,
"deleted": 0,
"id": 2
}
我不知道它是否是正确的方法,但它解决了这个问题。希望它可以帮助别人。