When querying a model with include, incase of no rows available, it is returning data with null values.
I know this problem has been posted many times before, but i have not found any conclusions till now.
Model.findOne({
where: { id: 1 },
include: [{model: Model1}]
})
Result i am getting is like
{
"id": null,
"name": null,
"age": null,
"model1": []
}
If i use raw: true, it is printing like
{
"id": null,
"name": null,
"age": null,
"model1.model1n": 0
}
One cause of this is if you exclude id from attributes. If you're using scopes or attributes in your includes or through tables, make sure you're returning the id primary key.
Another cause of this is if you return null in a custom get() getter function on the column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With