Forráskód Böngészése

Add thread limit to options function

sbkwgh 8 éve
szülő
commit
1e4937d5e2
1 módosított fájl, 8 hozzáadás és 4 törlés
  1. 8 4
      models/category.js

+ 8 - 4
models/category.js

@@ -18,19 +18,23 @@ module.exports = (sequelize, DataTypes) => {
 			associate (models) {
 				Category.hasMany(models.Thread)
 			},
-			includeOptions () {
+			includeOptions (threadLimit) {
 				let models = sequelize.models
-
-				return [{
+				let options = {
 					model: models.Thread, 
 					include: [
+						models.Category,
 						{ model: models.User, attributes: ['username', 'createdAt', 'id'] }, 
 						{
 							model: models.Post, limit: 1, include:
 							[{ model: models.User, attributes: ['username', 'id'] }]
 						}
 					]
-				}]
+				}
+
+				if(threadLimit) options.limit = threadLimit
+
+				return [options]
 			}
 		}
 	})