如何使用 Api 平台和 Angular 记录嵌入关系?

问题描述

他是我的观点:我有两个实体主题和编队。关系是 manyToOne :一个主题可以有多个编队,一个编队属于一个主题。 我希望能够创建一个新的编队并为这个新的编队选择现有的主题之一。我可以用 IRI 做到这一点,但我无法用 denormalisationContext 找到它。这是我的表:

形成

/**
 * @ApiResource(
 *     normalizationContext={"groups"={"formation:read"}},*     denormalizationContext={"groups"={"formation:write"}},* )
 * @ORM\Entity(repositoryClass=FormationRepository::class)
 */
class Formation
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"formation:read","formation:write"})
     */
    private $id;

    /**
     * @ORM\Column(type="string",length=255,nullable=true)
     * @Groups({"formation:read","formation:write"})
     */
    private $name;

    /**
     * @ORM\Column(type="string",length=500,"formation:write"})

    /**
     * @ORM\ManyToOne(targetEntity=Theme::class,inversedBy="formation")
     * @Groups({"formation:read","formation:write"})
     */
    private $theme;

主题


/**
 * @ApiResource()
 * 
 * @ORM\Entity(repositoryClass=ThemeRepository::class)
 */
class Theme
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string",length=1000,nullable=true)
     * 
     * 
     */
    private $description;

    /**
     * @ORM\OnetoMany(targetEntity=Formation::class,mappedBy="theme",orphanRemoval=true)
     */
    private $formation;

在 Angular 方面,我有一个经典的响应式表单,我写的主题字段:

                            <option *ngFor="let theme of themes" [value]="theme.name">
                                {{theme.name}}
                            </option>

但是当我尝试在 Formation 上发出 post 请求时,它不起作用:( 如果有其他人知道为什么吗?

提前非常感谢 我

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)