我正在使用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;
}
}
与预订相关的代码在实体中
/**
* @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;
}
一个预订有一个地方,一个地方可以有许多预订