New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not possible to create Many-to-One embedded entities that have constructor #2395
Comments
|
Thanks for taking the time and commenting. However, this is not the same issue. If I rewrite the bug with entities from your PR, the issue is with the not setting class Animal {
/** @var Zoo */
private $zoo;
/** @var string */
private $name;
public function __construct(Zoo $zoo, string $name) {...}
} and {
"animals": [
{"name": "Bug"}
]
} So the issue is that api-platform can't deserialize |
This looks really specific though and I'd create a custom DataPersister for such need. Are you sure that the normalizer doesn't work properly with Dtos? About constructors the support has been added in recent version, lmk if I need to reopen this. Thanks for your support all these years though :). |
Having the same issue right now in 2022, and found my own issue :) @soyuka probably you have a new recommendations now with new versions of APIP for this problem? |
Hello @soyuka any updates on this ? |
Let's consider the example from Behat tests of this repository.
We have
VoDummyCar
that has a collection ofVoDummyInspection[]
entities (with constructorpublic function __construct(bool $accepted, VoDummyCar $car...)
.We already have separate tests that create
VoDummyCar
andVoDymmyInspection
for particular carPOST /vo_dummy_car
core/features/serializer/vo_relations.feature
Lines 9 to 25 in f8693d1
POST /vo_dummy_inspections
core/features/serializer/vo_relations.feature
Lines 56 to 61 in f8693d1
What does not work?
Someone might want to create
VoDummyInspection
entities at the same time whenVoDummyCar
is being created, providing a nested array.It turned out, that such request does not work with ApiPlatform:
Expected result
Running the query above, I expect new
VoDummyCar
to be created as well as newVoDummyInspections
to be created for thisVoDummyCar
(in this case - just one entity).Actual Result
When I modify existing tests - nothing happens.
inspections
key from JSON is ignored (I have addedaddInspection
andremoveInspection
methods to make this property writable, but it didn't help).In my project, I get an error something like
Cannot create an instance of VoDummyInspection from serialized data because its constructor requires parameter \"car\" to be present.
Any suggestions about possible implementation?
The text was updated successfully, but these errors were encountered: