bedwetter
bedwetter copied to clipboard
Question on routes
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?
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.