-
-
Notifications
You must be signed in to change notification settings - Fork 923
Description
Let's consider the example from Behat tests of this repository.
We have VoDummyCar
that has a collection of VoDummyInspection[]
entities (with constructor public function __construct(bool $accepted, VoDummyCar $car...)
.
We already have separate tests that create VoDummyCar
and VoDymmyInspection
for particular car
POST /vo_dummy_car
core/features/serializer/vo_relations.feature
Lines 9 to 25 in f8693d1
And I send a "POST" request to "/vo_dummy_cars" with body: | |
""" | |
{ | |
"mileage": 1500, | |
"bodyType": "suv", | |
"make": "CustomCar", | |
"insuranceCompany": { | |
"name": "Safe Drive Company" | |
}, | |
"drivers": [ | |
{ | |
"firstName": "John", | |
"lastName": "Doe" | |
} | |
] | |
} | |
""" |
POST /vo_dummy_inspections
core/features/serializer/vo_relations.feature
Lines 56 to 61 in f8693d1
And I send a "POST" request to "/vo_dummy_inspections" with body: | |
""" | |
{ | |
"accepted": true, | |
"car": "/vo_dummy_cars/1" | |
} |
What does not work?
Someone might want to create VoDummyInspection
entities at the same time when VoDummyCar
is being created, providing a nested array.
It turned out, that such request does not work with ApiPlatform:
{
"mileage": 1500,
"bodyType": "suv",
"make": "CustomCar",
"insuranceCompany": {
"name": "Safe Drive Company"
},
"drivers": [],
"inspections": [
{
"performed": "2018-08-24 00:00:00",
"accepted": false
}
]
}
Expected result
Running the query above, I expect new VoDummyCar
to be created as well as new VoDummyInspections
to be created for this VoDummyCar
(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?