首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:无法为XXX实体生成IRI

错误:无法为XXX实体生成IRI
EN

Stack Overflow用户
提问于 2022-02-08 19:19:19
回答 1查看 216关注 0票数 -2

首先,对不起我的英语。

我正在尝试用API平台和Symfony在我的客户实体上写一篇文章。( get工作正常)

在写这篇文章时,我发现自己犯了这个错误:

“无法为”App\Entity\Customer“生成IRI。”

这是我的实体,我认为问题来自这里,但我找不到原因。

代码语言:javascript
复制
<?php

namespace App\Entity;

use ....


/**
 * @ORM\Entity(repositoryClass=CustomerRepository::class)
 */
#[ApiResource(
    collectionOperations: [
        'get' => ['method' => 'get'],
        'post' => ['method' => 'post'],
    ],
    itemOperations: [
        'get' => ['method' => 'get'],
        'put' => ['method' => 'put'],
        'delete' => ['method' => 'delete'],
    ],
    denormalizationContext: ['groups' => ['write_customer']],
    normalizationContext: ['groups' => ['read_customer']],
)]

class Customer
{
......
EN

回答 1

Stack Overflow用户

发布于 2022-03-04 23:38:19

生成IRI需要ID上的可见性,如果您有序列化组,则必须将这个组添加到id (primKey)中。

首先,确保您有一个工作良好的getId函数。然后,您可以将您的海运组添加到id中。

在这里,您可以在dokumetation中找到一个例子:https://api-platform.com/docs/core/serialization/#calculated-field

代码语言:javascript
复制
....
    denormalizationContext: ['groups' => ['write_customer']],
    normalizationContext: ['groups' => ['read_customer']],
....




/**
 * @var int The entity Id
 *
 * @ORM\Id
 * @ORM\GeneratedValue
 * @ORM\Column(type="integer")
 */
#[Groups("write_customer", read_customer)]
private $id;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71039677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档