Api 平台:实体级联上的订单
Api Platform : order on an entity cascade
有了Api平台,我们可以联合下单
use ApiPlatform\Core\Annotation\ApiResource;
/**
* @ApiResource(attributes={"order"={"author.username"}})
*/
class Book
{
...
但我想在实体级联上排序。
对于下面的例子,我用这个错误进行了测试:
* @ApiResource(
* attributes={
* "order"={"exercises.repetitions.id":"asc"}
* }
* )
[Semantical Error] line 0, col 422 near 'id ASC, rests_a6.id': Error: Class App\Entity\TrainingSerieExercise has no field or association named repetitions.id
TrainingSerie
实体:
* @ApiResource(
...
* attributes={
* "order"={"exercises.repetitions.id":"asc"}
* }
* )
*/
class TrainingSerie
{
...
/**
* @var TrainingSerieExercise[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\TrainingSerieExercise",
* mappedBy="serie",
* cascade={"persist"}
* )
* @Groups({
* "trainings_read",
* "training_series_read",
* "training_series_write",
* })
*/
private $exercises;
...
TrainingSerieExercise
实体:
...
class TrainingSerieExercise
{
...
/**
* @var TrainingSerieRepetition[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\TrainingSerieExerciseRepetition",
* mappedBy="exercise",
* cascade={"persist"},
* )
* @Groups({
* "training_series_read",
* "training_series_write",
* "training_serie_exercices_write",
* })
*/
private $repetitions;
...
TrainingSerieExerciseRepetition
实体:
class TrainingSerieExerciseRepetition
{
...
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({
* "training_series_read",
* })
*/
private $id;
...
在此之后 Doctrine doc 这将按 id:
排序 TrainingSerieExercise::$repetitions
class TrainingSerieExercise
{
...
/**
* @var TrainingSerieRepetition[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\TrainingSerieExerciseRepetition",
* mappedBy="exercise",
* cascade={"persist"},
* )
* @ORM\OrderBy({"id" = "ASC"})
* @Groups({
* "training_series_read",
* "training_series_write",
* "training_serie_exercices_write",
* })
*/
private $repetitions;
...
有了Api平台,我们可以联合下单
use ApiPlatform\Core\Annotation\ApiResource;
/**
* @ApiResource(attributes={"order"={"author.username"}})
*/
class Book
{
...
但我想在实体级联上排序。
对于下面的例子,我用这个错误进行了测试:
* @ApiResource(
* attributes={
* "order"={"exercises.repetitions.id":"asc"}
* }
* )
[Semantical Error] line 0, col 422 near 'id ASC, rests_a6.id': Error: Class App\Entity\TrainingSerieExercise has no field or association named repetitions.id
TrainingSerie
实体:
* @ApiResource(
...
* attributes={
* "order"={"exercises.repetitions.id":"asc"}
* }
* )
*/
class TrainingSerie
{
...
/**
* @var TrainingSerieExercise[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\TrainingSerieExercise",
* mappedBy="serie",
* cascade={"persist"}
* )
* @Groups({
* "trainings_read",
* "training_series_read",
* "training_series_write",
* })
*/
private $exercises;
...
TrainingSerieExercise
实体:
...
class TrainingSerieExercise
{
...
/**
* @var TrainingSerieRepetition[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\TrainingSerieExerciseRepetition",
* mappedBy="exercise",
* cascade={"persist"},
* )
* @Groups({
* "training_series_read",
* "training_series_write",
* "training_serie_exercices_write",
* })
*/
private $repetitions;
...
TrainingSerieExerciseRepetition
实体:
class TrainingSerieExerciseRepetition
{
...
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({
* "training_series_read",
* })
*/
private $id;
...
在此之后 Doctrine doc 这将按 id:
排序 TrainingSerieExercise::$repetitionsclass TrainingSerieExercise
{
...
/**
* @var TrainingSerieRepetition[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\TrainingSerieExerciseRepetition",
* mappedBy="exercise",
* cascade={"persist"},
* )
* @ORM\OrderBy({"id" = "ASC"})
* @Groups({
* "training_series_read",
* "training_series_write",
* "training_serie_exercices_write",
* })
*/
private $repetitions;
...