Skip to content

Comments

Update serialize.js to correct handling of relationships#3

Open
k8n wants to merge 2 commits intocaiotarifa:mainfrom
k8n:patch-1
Open

Update serialize.js to correct handling of relationships#3
k8n wants to merge 2 commits intocaiotarifa:mainfrom
k8n:patch-1

Conversation

@k8n
Copy link

@k8n k8n commented Nov 1, 2024

Corrects serialization of one-to-many relationship, e.g. when serializing a structure like this:

{
    "id": "5",
    "title": "Welcome!",
    "type": "calendar-event",
    "participantCalendars": [
        {
            "id": "9",
            "type": "calendar",
            "name": "Rando",
            "color": "#b1a0c6",
        },
        {
            "id": "11",
            "type": "calendar",
            "name": "Bobert",
            "color": "#404040",
        }
    ],
    "calendar": {
        "id": "5",
        "type": "calendar",
        "name": "Froo",
        "color": "#ff0000",
    }
}

In addition, fetchja will now correctly serialize empty nested objects to null. For example, the following structure ...

{
    "id": "5",
    "title": "Welcome!",
    "type": "calendar-event",
    "calendar": {}
}

... will be serialized as follows:

{
    "id": "5",
    "type": "calendar-event",
    "attributes": {
        "title": "Welcome!",
    },
    "relationships" : {
        "calendar": { "data": null }
    }
}

@k8n k8n changed the title Update serialize.js to correctly handle one-to-many relationships Update serialize.js to correct handling of relationships Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant