Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
    "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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading