Api platform filtration group by issue

51
May 28, 2022, at 1:30 PM

I'm using:

  • api platform 2.6.5
  • symfony 5.3.6
  • php 8.0.3

I trying to do custom filtration by subresource quantity. Problem what I encountered when I group resource it wrong display subresources (just 1 not all).

Result without any filtration:

"@id": "/api/formats/7",
      "@type": "Format",
      "title": "Cuda urody",
      "categories": [],
      "createdAt": "2021-12-02T12:53:18+01:00",
      "updatedAt": "2021-12-02T12:53:18+01:00",
      "seasons": [
        {
          "@id": "/api/seasons/7",
          "@type": "Season",
          "position": 0,
          "seasonNumber": "1"
        },
        {
          "@id": "/api/seasons/12",
          "@type": "Season",
          "position": 0,
          "seasonNumber": "2"
        }
      ]
...

Used filtration:

$alias = $queryBuilder->getRootAliases()[0];
$queryBuilder->groupBy($alias);

Result with filtration (missing subresource):

"@id": "/api/formats/7",
      "@type": "Format",
      "title": "Cuda urody",
      "categories": [],
      "createdAt": "2021-12-02T12:53:18+01:00",
      "updatedAt": "2021-12-02T12:53:18+01:00",
      "seasons": [
        {
          "@id": "/api/seasons/7",
          "@type": "Season",
          "position": 0,
          "seasonNumber": "1"
        }
      ]
...

Expectation: after using filter with grouping - get full subresources like in 1st example.

Yes I need use group in query to display filter results. Am I missing something or it's just api platform issue?

Probably problem is the way query is generated in api platform. I didn't notice problem when grouping Entity in Repository.

EDIT: I've managed to deal with this by adding on subresource (seasons)

fetch="EXTRA_LAZY"

so now it looks like

/**
 * @ORM\OneToMany(targetEntity=Season::class, mappedBy="format", fetch="EXTRA_LAZY")
 * @Groups({"format:read", "format:write"})
 * @Assert\Valid
 */
#[ApiSubresource]
private $seasons;

I'm not sure if it is the proper way, but it works for me.

READ ALSO
Why date comparison gives wrong result?

Why date comparison gives wrong result?

I am trying to give access to users in same specific datesFor example one of them started today and the comparison worked fine

49
How we can insert header and footer in google docs with google docs api using PHP code

How we can insert header and footer in google docs with google docs api using PHP code

I want to insert header and footer in my google docs with google docs api in PHP codeI am doing it like this-

45
Merge people profiles based on email match

Merge people profiles based on email match

I have an existing directory (php with xml datasource) which contains people information such as this:

60