Merge pull request #110 from jorilallo/queryperf

Query Improvements
This commit is contained in:
Jori Lallo
2017-07-06 23:22:16 -07:00
committed by GitHub
10 changed files with 100 additions and 115 deletions

View File

@@ -115,7 +115,32 @@ const Document = sequelize.define(
},
classMethods: {
associate: models => {
Document.belongsTo(models.User);
Document.belongsTo(models.Collection, {
as: 'collection',
foreignKey: 'atlasId',
});
Document.belongsTo(models.User, {
as: 'createdBy',
foreignKey: 'createdById',
});
Document.belongsTo(models.User, {
as: 'updatedBy',
foreignKey: 'lastModifiedById',
});
Document.hasMany(models.Star, {
as: 'starred',
});
Document.addScope(
'defaultScope',
{
include: [
{ model: models.Collection, as: 'collection' },
{ model: models.User, as: 'createdBy' },
{ model: models.User, as: 'updatedBy' },
],
},
{ override: true }
);
},
findById: async id => {
if (isUUID(id)) {