Просмотр исходного кода

Add includeOptions class method

sbkwgh 8 лет назад
Родитель
Сommit
ce0af9cadd
1 измененных файлов с 21 добавлено и 0 удалено
  1. 21 0
      models/thread.js

+ 21 - 0
models/thread.js

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