小编Kun*_*ara的帖子

Doctrine 分配错误:无法将 Doctrine\ORM\PersistentCollection 分配给属性

我有一个上传文件,我想从那里显示数据库中的所有类别,但我一直收到 EntityType 错误,我不知道之前为什么工作。

这是错误: Cannot assign Doctrine\ORM\PersistentCollection to property App\Entity\Category::$posts of type Doctrine\Common\Collections\ArrayCollection

<?php

declare(strict_types=1);

namespace App\Entity;

use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=CategoryRepository::class)
 */
class Category
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private int $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private string $name;

    /**
     * @ORM\OneToMany(targetEntity=Post::class, mappedBy="Category_id")
     */
    private ArrayCollection $Posts;

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

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

    public function …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

2
推荐指数
3
解决办法
1019
查看次数

标签 统计

doctrine-orm ×1

php ×1

symfony ×1