1

I have a page which bootstraps itself with a list of 25 objects prior to making a REST request for the entire list (234 objects in test).

Because I access the same query through two different entry points, I abstract into a function:

ideaListTrailingWeek: function index(req, limit){
    var user = req.user
    var Idea = req.db.models.dili_forum;

    var now = new Date()
    // set now to be 100 days ago because my data set is old
    now = dateHelper.addDays(now, -100)
    var weekAgo = dateHelper.addDays(now, -7)

    var promise = _.isUndefined(limit) ?
        Idea.qFind({ date_added: orm.gte(weekAgo) },{autoFetchLimit: 2}, ['-id']) :
        Idea.qFind({ date_added: orm.gte(weekAgo) },{autoFetchLimit: 2}, limit, ['-id'])

    return promise.then(function (ideas) {

        var ideasFinal = _.chain(ideas)
            .map(ideaTx.lightIdea)
            .value()

        return ideasFinal
    })
}

This is all working OK (picking the right promise and executing it). The model is

 Idea -many-> IdeaIndustry -one-> Industry
 Idea -one-> User -one-> Member

If I access with the call that bootstraps the page with the "limit"" first, the page loads fine. The Model is loaded to the proper depth. However the subsequent rest call comes through (picking the promise without the limit), and doesn't return any of the nested objects (not the first level User, nor the deeper objects).

If I reset the Node server and access through the REST call (picking the promise without the limit), the entire data set is loaded with proper depth.

I have set all my relationships up with the hasOne relationship, out of comfort of having used it that way in previous projects. That said, I plan to investigate the many relationship once I have this working properly. This project has a legacy DB built by offshore contractors with poor names, and mis-labeled fields. Models:

   var Idea = db.define('dili_forum', {
        id : Number,
        title : String,
        content : String,
        user_id : Number,
    }, {
        autoFetch: true
    }) ;

   var IdeaIndustry = db.define('teaser_industries', {
        id: Number,
        teaser_id: Number,
        sub_industry_id : Number
    }, {
        autoFetch: true
    }) ;

    var Industry = db.define('mas_flattened_industry', {
        industry_id: Number,
        industry_name : String,
        parent_industry_id: String,
        parent_industry_name: String,
        category_name: String
    }, {
        id: 'industry_id',
        autoFetch: true
    }) ;

I can post the user model chain if that will help. Here is how the relationships are set up:

    Idea.hasOne('user', User, {
        reverse: 'ideas'
        , field: 'user_id'
        , autoFetch: true
    })

    IdeaTicker.hasOne('idea', Idea, {
        reverse: 'tickers'
        , field: 'teaser_id'
        , autoFetch: true
    })

    IdeaIndustry.hasOne('idea', Idea, {
        reverse: 'industries'
        , field: 'teaser_id'
        , autoFetch: true
    })

    IdeaIndustry.hasOne('industry', Industry, {
        field: 'sub_industry_id'
        , autoFetch: true
    })

Any thoughts?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.