瀏覽代碼

Fix bug with replies and replyingTo associations, use separte column key

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

+ 1 - 1
models/post.js

@@ -14,7 +14,7 @@ module.exports = (sequelize, DataTypes) => {
 				Post.belongsTo(models.User)
 				Post.belongsTo(models.Thread)
 				Post.hasMany(models.Post, { as: 'Replies' })
-				Post.hasOne(models.Post, { as: 'ReplyingTo' })
+				Post.hasOne(models.Post, { as: 'ReplyingTo', foreignKey: 'ReplyId' })
 			},
 			includeOptions () {
 				let models = sequelize.models

+ 1 - 1
test/thread_post.js

@@ -279,7 +279,7 @@ describe('Thread and post', () => {
 			res.body.should.have.deep.property('User.username', 'username1')
 			res.body.should.have.deep.property('Thread.name', 'thread')
 			res.body.should.have.deep.property('ReplyingTo.User.username', 'username')
-			res.body.should.have.property('Replies', null)
+			res.body.should.have.property('Replies').that.deep.equals([])
 		})
 		it('should return any replies to a post', async () => {
 			let res = await replyAgent.get('/api/v1/post/1')