8000 Not possible to create Many-to-One embedded entities that have constructor · Issue #2395 · api-platform/core · GitHub
[go: up one dir, main page]

Skip to content
Not possible to create Many-to-One embedded entities that have constructor #2395
@maks-rafalko

Description

@maks-rafalko

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

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

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

  1. When I modify existing tests - nothing happens. inspections key from JSON is ignored (I have added addInspection and removeInspection methods to make this property writable, but it didn't help).

  2. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0