Override many to many association instead of adding new entries

is it possible to override the entries in a many-to-many association via the admin API?
I tried it with a basic update (PATCH) request and instead of overriding the association it just adds the new ones.

Before Update:

[GET] {apiBasePath}/product/91d7e5d1e77b48ae957d90f9a5210465

{
    "data": {
        "id": "91d7e5d1e77b48ae957d90f9a5210465",
        "properties": [
            {
                "id": "4a893ae509cc42ce9084a2ac55753bd6"
            }
        ]
    }
}

Update:

[PATCH] {apiBasePath}/product/91d7e5d1e77b48ae957d90f9a5210465

{
    "id": "91d7e5d1e77b48ae957d90f9a5210465",
    "properties": [
        {
            "id": "1e2569aa85c74f8baa3a85978b42a5ec"
        }
    ]
}

After Update:

[GET] {apiBasePath}/product/91d7e5d1e77b48ae957d90f9a5210465

{
    "data": {
        "id": "91d7e5d1e77b48ae957d90f9a5210465",
        "properties": [
            {
                "id": "4a893ae509cc42ce9084a2ac55753bd6",
                "id": "1e2569aa85c74f8baa3a85978b42a5ec"
            }
        ]
    }
}

Expected Result:

[GET] {apiBasePath}/product/91d7e5d1e77b48ae957d90f9a5210465

{
    "data": {
        "id": "91d7e5d1e77b48ae957d90f9a5210465",
        "properties": [
            {
                "id": "1e2569aa85c74f8baa3a85978b42a5ec"
            }
        ]
    }
}

>Solution :

It’s by design that setting associations is accumulative. If you need to remove associated data refer to the documentation.

Leave a Reply