lundi 22 juin 2015

How to set up a HasMany relationship for Ember.js on the node.js side

My app is set up with Ember as the front-end framework and a node.js back-end, using the express.js server. There is not server-side framework at play, so if I were to request a GET from /users, I am manually writing a sql statement to fetch the required users.

Now, the question is, I've set up a hasMany/BelongsTo relationship between an inspectionResultType(the parent) and inspectionResults(child).

App.InspectionResultType = DS.Model.extend({
    inspectionResultTypeID: DS.attr('number'),
    name: DS.attr('string'),
    ...
    inspectionResults: DS.hasMany('inspectionResult', {async: true}), // figure out how to make this work. 
    // inspectionResults: DS.hasMany('inspectionResult'),
});

App.InspectionResult = DS.Model.extend({
    inspectionResultID: DS.attr('string'),
    ...
    inspectionResultType: DS.belongsTo('inspectionResultType')
});

Now, InspectionResultTypes don't have their own route in the Ember app; they are only ever accessed from the record Page. So, in the record route, I am using an Ember RSVP to call inspectionResultTypes as a property, which works to fetch the inspectionResultTypes for sure, but shows no inspectionResults.

In my server logs, I notice this:

GET /inspectionResults?ids%5B%5D=2741&ids%5B%5D=2742&ids%5B%5D=2743&ids%5B%5D=2744 200 49597ms

(please ignore the 200 result value. That's wrong.)

So my question is this: how do I handle a GET request like this on the node.js side? There seem to be multiple id's and I don't think running several sql statements is the answer.




Aucun commentaire:

Enregistrer un commentaire