Parcourir la source

Add includeOptions class method

sbkwgh il y a 8 ans
Parent
commit
bed82c1e42
1 fichiers modifiés avec 15 ajouts et 0 suppressions
  1. 15 0
      models/post.js

+ 15 - 0
models/post.js

@@ -15,6 +15,21 @@ module.exports = (sequelize, DataTypes) => {
 				Post.belongsTo(models.Thread)
 				Post.hasMany(models.Post, { as: 'Replies' })
 				Post.hasOne(models.Post, { as: 'ReplyingTo' })
+			},
+			includeOptions () {
+				let models = sequelize.models
+
+				return [
+					{ model: models.User, attributes: ['username', 'createdAt', 'id'] }, 
+					{ model: models.Thread, include: [models.Category]} ,
+					{
+						model: models.Post, as: 'ReplyingTo', include:
+						[{ model: models.User, attributes: ['username', 'id'] }]
+					}, {
+						model: models.Post, as: 'Replies', include:
+						[{ model: models.User, attributes: ['username', 'id'] }]	
+					}
+				]
 			}
 		}
 	})