mercredi 13 décembre 2017

Can't access parent model value when building url for async loading of data

I have three models:

// mode/order.js
DS.Model.extend({
    start: DS.attr('string'),
    end: DS.attr('string'),
    referral: DS.hasMany('order/referral')
});

// model/order/referral.js
DS.Model.extend({
    stop: DS.attr('string'),
    go: DS.attr('string'),
    log: DS.belongsTo('order/log', {async: true})
});

// model/order/log.js
DS.Model.extend({
    log: DS.attr('string'),
    referral: DS.belongsTo('order/referral')

});

The referrals have only the id of a log and have been setup this way:

// serializers/order/referral.js
DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
    attrs: {
        log: { serialize: false, deserialize: 'ids'}
    }
});

I have an adapter setup to get an order and embedded referrals. All of this loads fine but I want the logs to load async:

model.referral[0].log

This causes the call to be made but I need the referral id as part of the url I build in

// adapters/order/log.js
DS.RESTAdapter.extend({
    urlForFindRecord (id, modelName, snapshot) {
        // build base url
            var  base_url = ....

            // ---- need referral field 'stop' to build log url ----
            base_url += referral.stop + '/log/' + id;

        return base_url
    }
});

the referral values don't get passed into urlForFindRecord for the log adapter. How can I get the referral values to make the url for the log call when requesting the log?




Aucun commentaire:

Enregistrer un commentaire