More tree

This commit is contained in:
Jori Lallo
2016-06-20 23:12:56 -07:00
parent 24e02bfdc4
commit 2c07d43f46
7 changed files with 46 additions and 37 deletions

View File

@ -34,10 +34,24 @@ const Atlas = sequelize.define('atlas', {
// const slugifiedTitle = slug(this.title);
// return `${slugifiedTitle}-${this.urlId}`;
// }
async buildStructure() {
// TODO
const rootDocument = await Document.findOne({ where: {
parentDocumentForId: null,
atlasId: this.id,
}});
return {
name: rootDocument.title,
id: rootDocument.id,
url: rootDocument.getUrl(),
children: null,
}
}
}
});
Atlas.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' });
Atlas.hasOne(Document, { as: 'rootDocument', foreignKey: 'rootDocumentForId', constraints: false });
Atlas.hasOne(Document, { as: 'parentDocument', foreignKey: 'parentDocumentForId', constraints: false });
export default Atlas;