dimanche 5 novembre 2017

javascript ember with sails

I'm working with ember js and sails js and i have a problem that drove me insane,

now i'm supposed to make a statistics page and handle the filtering process in the sails js

i have to explain it a little, well

i have a model for departments and another model for requests the relationship between these models is (request belongsTo department) for some reason my manager prevented me to make a (hasMany) relationship, now what i want to do is to loop through all the departments and store them in new Object, inside that loop i want to loop through all the requests by Using Request.count({where : { department : department.id }}) and get the number of requests for each department in the departments Array Of Object

i tried to do it as i explained but the problem is when i log the department inside the request loop it gives me the result as i imagined but when i add (.id) it shows me 'undefined'

Here is my code

Department.find().then((departments) => {
    report.departments = departments;
    Request.count({ department : departments.id}).exec(function countMe(err, count) {
       console.log(count);
    })
})

I'm so thankful for whoever tries to help me out, i've been struggling in this thing for like almost 7 hours and i'm getting crazy about it,

P.S : if there's any other approach to the idea i want to do please tell me i'm kind of beginner.




Aucun commentaire:

Enregistrer un commentaire