core
core copied to clipboard
Issue with link when creating (POST) a resource using a subresource
API Platform version(s) affected: 2.7.x
Description
#[ApiResource(
uriTemplate: '/libraries/{id}/books',
uriVariables: [
'id' => new Link(
fromClass: Library::class,
toProperty: 'library',
)
],
operations: [new GetCollection(), new Post()]
)]
class Book
Route
_api_/libraries/{id}/books_get_collection GET ANY ANY /api/libraries/{id}/books
_api_/libraries/{id}/books_post POST ANY ANY /api/libraries/{id}/books
Doctrine query to create the link to library
SELECT b0_.id AS id_0, b0_.name AS name_1, b0_.created_at AS created_at_2, b0_.library_id AS library_id_3
FROM book b0_
INNER JOIN library l1_
ON b0_.library_id = l1_.id
WHERE l1_.id = ?"
This query returns more than one row to get the library.
How to reproduce
You can use this "testing" project to reproduce the bug => https://github.com/loic425/test-api-platform-2.7/blob/main/tests/Controller/BookApiTest.php#L65
I don't get why POST would try to read data, for now we didn't try to use subresources to do writes.
@soyuka Yes, but that'd be awesome ;)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.