php - 更新产品删除错误刚刚创建的数量
问题描述
我对 API 平台有疑问。我有一个产品实体和一个数量实体。我为我的 Angular 应用程序使用 API Platform 一个 API。
一个产品可以有多个数量,一个数量只能有一个产品。
在我的角度形式中,如果我创建一个链接到它工作的产品的数量(它是在数据库中创建的)。之后,当我更新此产品时,这些先前的数量被删除(即使我已将先前添加的数量的 IRI 添加到更新前的产品数量中)。
这是一些代码:
数量.php
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
/**
* @ApiResource()
* @ApiFilter(OrderFilter::class, properties={"packing": "ASC"})
* @ORM\Entity(repositoryClass="App\Repository\QuantityRepository")
*/
class Quantity
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="quantities")
* @ORM\JoinColumn(nullable=false)
*/
private $product;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Ingredient")
* @ORM\JoinColumn(nullable=false)
*/
private $ingredient;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Packing")
* @ORM\JoinColumn(nullable=false)
*/
private $packing;
/**
* @ORM\Column(type="string", length=255)
*/
private $value;
产品.php
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Annotation\ApiSubresource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Dompdf\Dompdf;
use Dompdf\Options;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
* @ORM\HasLifecycleCallbacks()
* @ApiResource(
* collectionOperations={
* "get",
* "post"
* },
* itemOperations={
* "get",
* "put",
* "delete",
* "api_products_get_pdf_by_category" = {
* "method"="GET",
* "controller"="ProductController::class",
* },
* "api_products_get_pdf_by_list" = {
* "method"="GET",
* "controller"="ProductController::class",
* },
* "duplicate" = {
* "method"="GET",
* "controller"="ProductController::class",
* },
* "api_products_make_pdf" = {
* "method"="GET",
* "controller"="ProductController::class",
* }
* },
* normalizationContext={"groups"={"product"}}
* )
* @ApiFilter(OrderFilter::class, properties={"name", "id", "modifiedAt"})
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "name": "partial", "productCategories.name": "exact", "enable": "exact", "bakeryProductsOverride.bakery.id":"exact"})
*/
class Product
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"product"})
*/
private $id;
/* ... OTHERS PROPERTIES CUTTED ... */
/**
* @ORM\OneToMany(targetEntity="App\Entity\Quantity", mappedBy="product", orphanRemoval=true)
* @Groups({"product"})
*/
private $quantities;
}
解决方案
我的错。与 API 平台无关。Angular 中的调用顺序有误。对不起,噪音。
推荐阅读
- mysql - POST完成后如何从MySQL获取数据
- firebase - Flutter FirebaseUser 如何访问用户数据
- git - 如何对 gitea 配置进行版本化?
- eloquent - Laravel 5.8:总是给出多个主键语法或访问冲突错误
- node.js - MongoDB嵌套数组聚合正确
- spring-boot - 使用 JPA 的 Spring Boot Batch 动态多数据源
- netlogo - Netlogo:乌龟明显的古怪行为
- ios - SwiftUI - 如果 TabView 嵌套在 NavigationLink 中,TabView 内的视图会在一秒钟后跳转
- python - 如何概括导入脚本
- nlp - 为什么运行“python run_squad.py”不起作用?