【发布时间】:2017-08-20 10:07:58
【问题描述】:
我正在尝试向我的基地插入一条线,从邮递员到带有一些外键的本地 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;
}
以及以外键为目标的实体:
<?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;
}
最后是我的 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
}
请帮忙,我做错了什么?
【问题讨论】:
-
添加控制器代码
-
也许:@ORM\ManyToOne(targetEntity="AppBundle\Entity\InterventionType")
-
@Cerad,需要有这种关系,但我和朋友解决了这个问题。我已经更改了我的控制器并编辑了我创建对象的方式,所以没关系
标签: api symfony doctrine-orm