I don't know why i cant get all data of subject that relate from student, The only data that display on response is the last id of student model, I tried to put console.log(subject) and i get the desired result but i dont know why i cant display it on response
const results = {
student: null,
subject: null,
}
const student = await StudentModel.getById(id)
if(student){
for(let i = 0; i<=student.length - 1; i++){
subject= await SubjectModel.getByStudentId(student[i]._id)
console.log(subject)
subject.append(subject)
}
}
results.subject= subject
res.json(data)
current result
student:[
{
id: 1,
description: student 1
},
{
id: 2,
description: student 2
}
],
subject:[
{
studentid: 2,
description: subject 2
}
]
desired result
result
student:[
{
id: 1,
description: student 1
},
{
id: 2,
description: student 2
}
],
subject:[
{
studentid: 1,
description: subject 1
},
{
studentid: 2,
description: subject 2
}
]
Update when I tried to implement append i received this error
error: uncaughtException: subject.append is not a function