API Platform version(s) affected: 2.5.5
Description
After updating the api-platform/core from version 2.5.4 to 2.5.5, all the entity subresources on OneToMany relations, when a custom identifier is set, stopped returning results. Subresources on ManyToMany relations, with custom identifier, work fine.
How to reproduce
This is a simplified example of a basic entity configuration in order to reproduce the issue:
Main Entity - Article:
/**
* @ApiResource()
* ...
*/
class Article
{
/**
* @ApiProperty(identifier=false)
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* ...
*/
private $id;
/**
* @ApiProperty(identifier=true)
* @ORM\Column(type="string", length=100)
* ...
*/
private $slug;
/**
* @ApiSubresource
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="article")
* ...
*/
private $comments;
/**
* @ApiSubresource
* @ORM\ManyToMany(targetEntity="App\Entity\Category", inversedBy="articles")
*/
private $categories;
}
Related Entity - Comment (OneToMany):
/**
* @ApiResource()
*/
class Comment
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Article", inversedBy="comments")
* @ORM\JoinColumn(nullable=false)
*/
private $article;
}
Related Entity - Category (ManyToMany):
/**
* @ApiResource()
*/
class Category
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Article", mappedBy="categories")
*/
private $articles;
}
Possible Solution
The src/Bridge/Doctrine/Orm/SubresourceDataProvider.php was updated on the version 2.5.5. The code on the previous version (2.5.4) didn't have this issue.
@dunglas this is a real bug. I have the same problem with an uuid identifier.
Probably comes from https://github.com/api-platform/core/pull/3396 then. Does https://github.com/api-platform/core/pull/3529 fixes your issue ? Could you help by adding a failing behat test covering your use case ?
Probably comes from #3396 then. Does #3529 fixes your issue ? Could you help by adding a failing behat test covering your use case ?
@soyuka #3529 does fix the error.
@soyuka I've already posted solution for this on #1542 platform issue tracker, sorry for delay, can you guys confirm it's doesn't break anything else? While #3529 uses different approach, this fix adds further optimized query but needs to be tested with multiple level of sub-resources.
@mahmoodbazdar kindly have a look, we all are taking about same issue.
Can someone merge that fix to solve this issue? I can't wait for that :)
https://github.com/api-platform/core/pull/3529
@soyuka I have the problem too, #3529 fix the error, can we hope a merge and a production tag ?
Most helpful comment
@soyuka #3529 does fix the error.