微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何使用 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 举报,一经查实,本站将立刻删除。