有一个Offer实体
* @ApiResource(
* normalizationContext={"groups"={"offer:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"offer:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get",
* "put"={"security"="is_granted('ROLE_USER')"},
* "delete": {
* "security"="is_granted('ROLE_USER')"
* }
* },
* collectionOperations={
* "get",
* "post"={
* "security"="is_granted('ROLE_USER')"
* }
* },
* attributes={
* "order"={"id": "DESC"}
* },
* )
class Offer
{
...
/**
* @var Collection страны оффера
*
* @ManyToMany(targetEntity=Country::class)
* @JoinTable(name="offers_countries",
* joinColumns={@JoinColumn(name="offer_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="country_id", referencedColumnName="id")}
* )
* @Assert\NotBlank
* @Assert\NotNull
* @Assert\Count(min=1)
* @Groups({"offer:read", "offer:write"})
* @ApiSubresource(maxDepth=1000)
*/
private Collection $countries;
/**
* @return Country[]|ArrayCollection<Country>
*/
public function getCountries()
{
return $this->countries;
}
/**
* @param Country $country
* @return $this
*/
public function addCountry(Country $country): self
{
if (!$this->countries->contains($country)) {
$this->countries->add($country);
}
return $this;
}
...
}
使用诸如https://example.com/api/offers/1 "countries": ["/api/countries/10"] 之类的 PUT 请求 ,将 ID 为 10 的国家/地区添加到现有国家/地区。告诉我出了什么问题。谢谢