Saving related objects in API Platform

别来无恙 提交于 2020-01-15 09:36:05

问题


I am new to API Platform and Symfony 4, I have a situation where we have 3 entity related to each other: User, Jobseeker, JobseekerLocation so when we need add register new Jobseeker can we make entry in related table automatically? Some kind of triggering.

Or we should make 3 API call to reach and save the data?


回答1:


Use the @Groups()

https://api-platform.com/docs/core/serialization/

/**
 * @ApiResource()
 */ 
class User {
    /**
    * @Groups({"registration"})
    * @ORM\ManyToOne/OneToOne(...)
     */
    private $jobSeeker;
}


/**
 * @ApiResource()
 */ 
class JobSeeker {
    /**
    * @Groups({"registration"})
    * @ORM\ManyToOne(...)
     */
    private $jobSeekerLocation;
}

/**
 * @ApiResource()
 */ 
class JobSeekerLocation {

    /**
    * @Groups({"registration"})
    * @ORM\Column(...)
     */
    private $city;
}


来源:https://stackoverflow.com/questions/53867870/saving-related-objects-in-api-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!