缺少hydra:api中的总项

问题描述 投票:-3回答:1

我目前遇到无法解决的问题。我有一个像这样定义的symfony / api-platform实体:

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ORM\Entity
 * @ApiResource(
 *     normalizationContext={"groups"={"node_read"}},
 *     denormalizationContext={"groups"={"node_write"}},
 *     collectionOperations={
 *          "get"={"method"="GET"},
 *          "post"={"method"="POST", "security"="is_granted('ROLE_ADMIN')"}
 *     },
 *     itemOperations={
 *          "get"={"method"="GET"},
 *          "put"={"method"="PUT", "security"="is_granted('ROLE_ADMIN')"},
 *          "patch"={"method"="PATCH", "security"="is_granted('ROLE_ADMIN')"},
 *          "delete"={"method"="DELETE", "security"="is_granted('ROLE_ADMIN')"}
 *     }
 * )
 * @ApiFilter(ExistsFilter::class, properties={"parent"})
 */
class Node
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"node_read"})
     */
    private ?int $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups({"node_read", "node_write"})
     */
    private string $key;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups({"node_read", "node_write"})
     */
    private string $label;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups({"node_read", "node_write"})
     */
    private string $type;

    /**
     * One Category has Many Categories.
     *
     * @OneToMany(targetEntity="Node", mappedBy="parent")
     * @Groups({"node_read"})
     */
    private Collection $children;

    /**
     * Many Nodes have One Node.
     *
     * @ManyToOne(targetEntity="Node", inversedBy="children")
     * @JoinColumn(name="parent_id", referencedColumnName="id")
     * @Groups({"node_write"})
     */
    private ?Node $parent;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private string $description;

    public function __construct()
    {
        $this->children = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getParent(): ?Node
    {
        return $this->parent;
    }

    public function setParent(?Node $parent): self
    {
        $this->parent = $parent;

        return $this;
    }

    public function getChildren(): Collection
    {
        return $this->children;
    }

    public function setChildren(Collection $children): self
    {
        $this->children = $children;

        return $this;
    }

    public function getKey(): string
    {
        return $this->key;
    }

    public function setKey(string $key): self
    {
        $this->key = $key;

        return $this;
    }

    public function getLabel(): string
    {
        return $this->label;
    }

    public function setLabel(string $label): self
    {
        $this->label = $label;

        return $this;
    }

    public function getType(): string
    {
        return $this->type;
    }

    public function setType(string $type): self
    {
        $this->type = $type;

        return $this;
    }

    public function getDescription(): string
    {
        return $this->description;
    }

    public function setDescription(string $description): self
    {
        $this->description = $description;

        return $this;
    }
}

在对集合进行调用时,在开发环境和生产之间我得到了不同的结果。

在产品环境中,api缺少hydra元数据密钥hydra:total

开发环境中的结果:

context: "/api/contexts/Node"
@id: "/api/nodes"
@type: "hydra:Collection"
hydra:member: [{@id: "/api/nodes/1", @type: "Node", id: 1, key: "risk-of-rain-2", label: "Risk Of Rain 2",…},…]
hydra:totalItems: 2
hydra:view: {@id: "/api/nodes?exists%5Bparent%5D=false", @type: "hydra:PartialCollectionView"}
hydra:search: {@type: "hydra:IriTemplate", hydra:template: "/api/nodes{?exists[parent]}",…}

prod env结果:

@id: "/api/nodes"
@type: "hydra:Collection"
hydra:member: [{@id: "/api/nodes/12", @type: "Node", id: 12, key: "feedback", label: "Feedback", type: "Game",…},…]
hydra:view: {@id: "/api/nodes?exists%5Bparent%5D=false", @type: "hydra:PartialCollectionView"}
hydra:search: {@type: "hydra:IriTemplate", hydra:template: "/api/nodes{?exists[parent]}",…}

正如您在产品中看到的,我是键hydra:totalItems: 2的错位键,它使我可以进行react-admin工作。

我已经比较了项目撰写者的依赖性和PHP版本,并且prod是ISO到dev env。

php symfony api-platform.com
1个回答
-1
投票

我发现我的问题与提供的源代码根本无关,但与部署有关。

Rsync没有删除项目的已删除文件,并且我有一个过量的Dataprovider。

解决方案是在rsync命令中使用--delete选项。

© www.soinside.com 2019 - 2024. All rights reserved.