bedwetter icon indicating copy to clipboard operation
bedwetter copied to clipboard

Question on routes

Open casalot opened this issue 8 years ago • 1 comments

If I have two entity models as follows:

module.exports = {
  identity: 'assessment',
  attributes: {
  id: {
      columnName: 'assessmentId',
      type: 'integer',
      primaryKey: true,
      autoIncrement: true,
      unique: true
    },
    questionnaire: {
      columnName: 'questionnaireId',
      model: 'questionnaire'
  }
}
module.exports = {
  identity: 'questionnaire',
  attributes: {
    id: {
      columnName: 'questionnaireId',
      type: 'integer',
      primaryKey: true,
      autoIncrement: true,
      unique: true
    },
    title: {
      type : 'string',
      required: true,
      maxLength: 100
    },
    assessments: {
      collection: 'assessment',
      via: 'questionnaire'
    }
  }
}

I can use the route GET /api/csqa/assessments?questionnaire=1 to get all assessments link to questionnaire 1.

Butt, how would I specify the inverse. i.e. getting all questionnaires used by assessment 1?

casalot avatar Jul 14 '16 09:07 casalot

I would use a "populate" route for that, GET /api/csqa/assessment/1/questionnaires or possibly, GET /api/csqa/assessment/1?populate=questionnaires.

The latter should include the assessment and its questionnaires, while the former should just return the array of questionnaires.

devinivy avatar Jul 14 '16 12:07 devinivy