Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update serialize.js to correct handling of relationships #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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