Msgstr "Ожидаемое значение типа ... для поля ассоциации ..., вместо этого получено \" Doctrine \\ Common \\ Collections \\ ArrayCollection \ "." - PullRequest
0 голосов
/ 24 марта 2019

Я использую Api_plateform и получаю эту ошибку, когда пытаюсь вставить место в резервацию

Expected value of type \"App\\Entity\\Place\" for association field \"App\\Entity\\Reservation#$placeId\", got \"Doctrine\\Common\\Collections\\ArrayCollection\" instead.

добавить функцию, связанную с моим резервированием



    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\place", inversedBy="reservation")
     * @ORM\JoinColumn(nullable=false)
     */
    private $placeId;

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

    /**
     * @return Collection|place[]
     */
    public function getPlaceId(): Collection
    {
        return $this->placeId;
    }

    public function addPlaceId(place $placeId): self
    {
        if (!$this->placeId != $placeId) {
            $this->placeId = $placeId;
            $placeId->setReservation($this);
        }

        return $this;
    }

    public function removePlaceId(place $placeId): self
    {
        if ($this->placeId->contains($placeId)) {
            $this->placeId->removeElement($placeId);
            // set the owning side to null (unless already changed)
            if ($placeId->getReservation() === $this) {
                $placeId->setReservation(null);
            }
        }

        return $this;
    }
}

код бронирования на месте Entity

 /**
     * @ORM\OneToMany(targetEntity="App\Entity\Reservation", mappedBy="placeId")
     */
    private $reservation;

    public function getReservation()
    {
        return $this->reservation;
    }

    public function setReservation(?Reservation $reservation): self
    {
        $this->reservation = $reservation;

        return $this;
    }

бронирование имеет одно место, а место может иметь много бронирований

...