johnhamelink
10/24/2012 - 12:39 PM

CRUD.js


    if(req.api.join != null && req.api.count == false)
        Object.keys(req.api.join).some(function (key){
            var column = req.api.join[key];
            var schema = req.api.model.schema.tree;
            console.log(schema);
            if(typeof schema[column] != "undefined") {
                // ObjectId
                if(typeof schema[column].ref != 'undefined' ) {
                    query.populate(column);
                }
                // Array of objectId
                else if(typeof schema[column][0] != 'undefined' && typeof schema[column][0].ref != 'undefined'){
                    query.populate(column);
                }
            }
        });

    this.runSearch(query, req, res, callback);