Skip to content

Commit bfe4c5e

Browse files
committed
add realtionshipAttributes filtering
1 parent 8c8e0a9 commit bfe4c5e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/baseController.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class Controller {
2929
'handleReview',
3030
'handlePublish',
3131
'get',
32-
'getExcludedAttributes'
32+
'getExcludedAttributes',
33+
'generateRelationshipAttributeClause'
3334
).forEach(methodName => {
3435
this[methodName] = this[methodName].bind(this)
3536
})
@@ -141,6 +142,14 @@ class Controller {
141142
return null
142143
}
143144

145+
generateRelationshipAttributeClause (req, modelName) {
146+
if (!req) return null
147+
const {fields} = req.query
148+
if(!fields) return null
149+
const attributes = fields[modelName] ? fields[modelName].split(',') : null
150+
return attributes
151+
}
152+
144153
// construct a Sorting Condition(value for sequelize sort: key) based on req.query.sort
145154
generateSortingCondition (req) {
146155
if (!req.query.sort) return []
@@ -177,7 +186,8 @@ class Controller {
177186

178187
const includeObj = {
179188
model: model.target,
180-
where: this.generateRelationshipWhereClause(req, modelName)
189+
where: this.generateRelationshipWhereClause(req, modelName),
190+
attributes: this.generateRelationshipAttributeClause(req, modelName)
181191
}
182192

183193
if (model.isAliased) {

0 commit comments

Comments
 (0)