var result = {}; var results = {}; var student_id = {}; var result3 = {}; var condition2 = { where : {} } if(classId) condition2.where.class_id = parseInt(classId); sails.log(condition2); var list_student = await Student.find(condition2); //get id student for(i in list_student){ student_id[i] = list_student[i].id; result3[list_student[i].id] = list_student[i].class_id; } //covert to array results = Object.keys(student_id).map(function(key) { return '' + student_id[key] + ''; }); var condition = { where : {id : results}, select: ['full_name', 'email', 'phone', 'active', 'address'], sort : 'full_name asc' }; if(isDeleted) condition.where.is_deleted = parseInt(isDeleted); if(keyword) condition.where.full_name = keyword.trim(); sails.log(condition); //query get user in student var list_user_student = await User.find( condition ); //push users info to object student for(i in list_user_student){ result[list_user_student[i].id] = list_user_student[i]; } //push class_id from student table to object student for(i in result){ result[i].class_id = result3[i]; } return result;