Tidy, move recent documents to query scope

This commit is contained in:
Tom Moor
2017-07-06 22:02:55 -07:00
parent f08ca8d460
commit b854c2ca53
7 changed files with 46 additions and 64 deletions

View File

@ -60,6 +60,16 @@ const Collection = sequelize.define(
as: 'documents',
foreignKey: 'atlasId',
});
Collection.addScope('withRecentDocuments', {
include: [
{
as: 'documents',
limit: 10,
model: models.Document,
order: [['updatedAt', 'DESC']],
},
],
});
},
},
instanceMethods: {