如何绕过错误“无效类型“ json_array””

时间:2019-12-18 10:44:09

标签: json symfony symfony4

我有一个实体:

<?php

namespace App\Entity\Aero;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\Aero\ScheduleRepository")
 */
class Schedule
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="date")
     */
    private $dateOfFlight;

    /**
     * @ORM\Column(type="json")
     */
    private $timeOfFlightAndStations = [];

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

    public function getDateOfFlight(): ?\DateTimeInterface
    {
        return $this->dateOfFlight;
    }

    public function setDateOfFlight(\DateTimeInterface $dateOfFlight): self
    {
        $this->dateOfFlight = $dateOfFlight;

        return $this;
    }

    public function getTimeOfFlightAndStations(): ?array
    {
        return $this->timeOfFlightAndStations;
    }

    public function setTimeOfFlightAndStations(array $timeOfFlightAndStations): self
    {
        $this->timeOfFlightAndStations = $timeOfFlightAndStations;

        return $this;
    }
}

当我尝试通过con make:entity添加类型为json_array的字段时,显示错误消息:

[ERROR] Invalid type "json_array".

我的计算机说“ json_array”类型无效,但也说它在有效类型列表中。怎么可能?

请帮帮我,如何处理此错误?

1 个答案:

答案 0 :(得分:0)

通过手动添加“ json_array”而不是以下位置的“ json”来解决此问题:

  /**
   * @ORM\Column(type="json_array")
   */