Symfony api平台有很多持久性
我需要与api平台保持多个关系,但我遇到了一个错误,我尝试了cascade={“persist”}和group 当我发送带有对象的请求时,我得到;不允许属性“idVehicles”的嵌套文档。用虹膜代替Symfony api平台有很多持久性,symfony,api-platform.com,Symfony,Api Platform.com,我需要与api平台保持多个关系,但我遇到了一个错误,我尝试了cascade={“persist”}和group 当我发送带有对象的请求时,我得到;不允许属性“idVehicles”的嵌套文档。用虹膜代替 { "name": "carl", "lastName": "abs", "idVehicles": [ {
{
"name": "carl",
"lastName": "abs",
"idVehicles": [
{
"license": "1212121"
}
]
}
这是我的用户实体:
/**
* Users
*
* @ORM\Table(name="users")
* @ORM\Entity
* @ApiResource(
* attributes={"pagination_enabled"=false},
* normalizationContext={"groups"={"users_read"}},
* denormalizationContext={"groups"={"users_write"}},
* )
*/
class Users
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="users_id_seq", allocationSize=1, initialValue=1)
* @Groups({"users_read", "users_write"})
*/
private $id;
/**
* @var string|null
*
* @ORM\Column(name="name", type="string", length=128, nullable=true)
* @Groups({"users_read", "users_write"})
*/
private $name;
/**
* @var string|null
*
* @ORM\Column(name="last_name", type="string", length=128, nullable=true)
* @Groups({"users_read", "users_write"})
*/
private $lastName;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Vehicles", mappedBy="idUsers", cascade={"persist"})
* @Groups({"users_read", "users_write"})
*/
private $idVehicles;
}
这是我的车辆实体:
/**
* Users
*
* @ORM\Table(name="users")
* @ORM\Entity
* @ApiResource(attributes={"pagination_enabled"=false})
*/
class Users
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="vehicles_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var string|null
*
* @ORM\Column(name="license", type="string", length=16, nullable=true, cascade={"persist"})
* @Groups({"users_read", "users_write"})
*/
private $license;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Users", inversedBy="idUsers")
* @ORM\JoinTable(name="users_vehicles",
* joinColumns={
* @ORM\JoinColumn(name="id_vehicles", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="id_users", referencedColumnName="id")
* }
* )
*/
private $idUsers;
您确定要更新架构吗?我测试您的代码,它正在工作您的
车辆
实体称为用户