瀏覽代碼

Reload notification returned from class method

sbkwgh 8 年之前
父節點
當前提交
b5f4162c74
共有 1 個文件被更改,包括 9 次插入2 次删除
  1. 9 2
      models/Notification.js

+ 9 - 2
models/Notification.js

@@ -17,7 +17,7 @@ module.exports = (sequelize, DataTypes) => {
 			},
 			//Props fields: user, post, mention
 			async createMention (props) {
-				let { MentionNotification, User } = sequelize.models
+				let { MentionNotification, User, Post } = sequelize.models
 
 				let user = await User.findOne({ where: { username: props.mention } })
 				if(!user) return null
@@ -31,7 +31,14 @@ module.exports = (sequelize, DataTypes) => {
 				await notification.setMentionNotification(mentionNotification)
 				await notification.setUser(user)
 
-				return notification
+				let reloadedNotification = await notification.reload({
+					include: [{
+						model: MentionNotification,
+						include: [Post, { model: User, attributes: ['createdAt', 'username', 'color'] }]
+					}]
+				})
+
+				return reloadedNotification
 			}
 		}
 	})