Explorar el Código

Add includeOptions class method

sbkwgh hace 8 años
padre
commit
bed82c1e42
Se han modificado 1 ficheros con 15 adiciones y 0 borrados
  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'] }]	
+					}
+				]
 			}
 		}
 	})