Response Body Keys on Nodejs is Incomplete

Issue

So I’m using Node.js, Express.js, and Sequelize on our API endpoints. We have encountered a problem where the response body keys are getting cut off.

Here’s the example GET response:

{
    "error": false,
    "data": [
        {
            "id": "3c6b9a8a-cbea-4daa-b0a1-22608d881837",
            // health_appointment_assigned_to_user is a Foreign Key
            "health_appointment_assigned_to_user": {
                "user_id": "fb4a5104-fc9e-4f4f-96d8-5a5c9e2726e5",
                "user_profiles": {
                    "user_profile_": "f0f90435-eebb-417f-b78d-d45e01f518a5",
                    "user_id": "fb4a5104-fc9e-4f4f-96d8-5a5c9e2726e5",
                    "first_name": "Josha",
                    "middle_name": "Galgo",
                    "last_name": "Galga",
                    "extension_nam": null,
                    "full_name": "Josha G. Galga",
                    "birth_date": "2022-09-14T00:00:00.000Z",
                    "gender": "Female",
                    "house_street": "data here",
                    "barangay": "data here",
                    "municipality": "data here",
                    "province": "data here",
                    "region": "data here",
                    "full_address": "data here",
                    "contact_numbe": "09211234567",
                    "image": "",
                }
            },
            // health_appointment_assigned_to_physician is a Foreign Key
            "health_appointment_assigned_to_physician": {
                "user_id": "a5ad3552-6d19-4dd3-b6b9-8f93bab0739f",
                "user_profiles": {
                    "user_pro": "027bfff1-a680-4dd7-a556-74916bf7ccaa",
                    "user_id": "a5ad3552-6d19-4dd3-b6b9-8f93bab0739f",
                    "first_na": "Melanie",
                    "middle_n": "Misoka",
                    "last_nam": "Martinez",
                    "extensio": null,
                    "full_nam": "Melanie M. Martinez",
                    "birth_da": "2001-01-21T00:00:00.000Z",
                    "gender": "data here",
                    "house_st": "data here",
                    "barangay": "data here",
                    "municipa": "data here",
                    "province": "data here",
                    "region": "NCR",
                    "full_add": "data here",
                    "contact_": "09211234567",
                    "image": "",
                }
            }
        }
    ],
    "message": "message here"
}

So as you can see, the response body keys are getting cut off for no reason at all. We have investigated the models and there doesn’t seem to be a problem here. And then, keys like "user_pro" are cut off and the original is "user_profile_id".

I also tried this solution. But it doesn’t seem to work also with this solution. Any insights here would be appreciated!

Solution

This is common issue in Sequelize. Try adding include: [{ separate: true, model: "Model name" }] in your code. Note that only HasMany associations support include.separate.

reference: https://github.com/sequelize/sequelize/issues/9684#issuecomment-1143442967

Answered By – Paul Tulod

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published