I've got a model I'm trying to query and I'm trying to include some very nested models (which their relation varies between hasOne to hasMany) to it, yet it seems that from a certain level the object comes back and an empty model
const parent = Parent.findByPk(id, {include: ["anotherChild",
{model: Child1, as: "child1", include: [
{model: Child2, as: "children2", include: [
{model: Child3, as: "child3", include: [
{model: Child4, as: "children4", include: [
{model: Child5, as: "children5"}
]}
]}
]}
]}
]});
When I try to print the most nested child, I receive a model instance but with no values (there are matching results, otherwise it would also just set them as null)
console.log(parent.child1.children2[0].child3.children4[0].children5[0]);
// prints:
// Child5 {
// dataValues: { '': null },
// _previousDataValues: { '': null },
// ....
// }
when I try to separate the query it does work
const parent = Parent.findByPk(id, {include: ["anotherChild", {model: Child1, as: "child1"}]});
const fromChild1 = Child1.findByPk(parent.child1.id, include: [
{model: Child2, as: "children2", include: [
{model: Child3, as: "child3", include: [
{model: Child4, as: "children4", include: [
{model: Child5, as: "children5"}
]}
]}
]}
]
);
result in the following value:
console.log(fromChild1.children2[0].child3.children4[0].children5[0]);
// prints:
// Child5 {
// dataValues: { 'realKey': 'realValue', 'realData': 'someData'... },
// _previousDataValues: { 'realKey': 'realValue, 'realData': 'someData'... },
// ....
// }
Why is that, and how could I get over that? (using {all: true, nested: true} is not possible due to belongsTo / belongsToMany relationships between them)