Я хочу использовать классы Product и Price со ссылками один ко многим. Это мой продукт класса.
/**
* @ApiResource
*
* @Document
*/
class Product
{
/**
* @ODM\Id(strategy="INCREMENT", type="integer")
*/
private $id;
/**
* @ODM\Field(type="string")
* @Assert\NotBlank
*/
public $name;
/**
* @ODM\ReferenceMany(targetDocument=Price::class, mappedBy="product", cascade={"all"}, storeAs="id")
*/
public $prices ;
public function __construct()
{
$this->prices = new ArrayCollection();
}
//getter and setter of id...
}
Это класс цены
/**
* @ApiResource
*
* @ODM\Document
*/
class Price
{
/**
* @ODM\Id(strategy="INCREMENT", type="integer")
*/
private $id;
/**
* @ODM\Field(type="float")
* @Assert\NotBlank
* @Assert\Range(min=0, minMessage="The price must be superior to 0.")
* @Assert\Type(type="float")
*/
public $price;
/**
* @Assert\Type(type="integer")
*/
private $discount;
/**
* @ODM\ReferenceOne(targetDocument=Product::class, inversedBy="prices", storeAs="id")
*/
public $product;
Я могу поставить и получить цену с id = 1, но когда я хочу поместить Product в swagger ui, я использую эту ссылку.
{
"name": "productno1",
"prices": [
"/api/prices/1/"
]
}
Это дает 201. Я могу проверить, что БД хранится. Название продукта productno1, но раздел цены пуст. Может кто-нибудь помочь с тем, что не так?