updated relation to one-to-many

This commit is contained in:
notnull 2019-07-09 12:23:10 -04:00
parent bd5a7ef113
commit 31087e4be5
3 changed files with 18 additions and 11 deletions

4
.prettierrc Normal file
View File

@ -0,0 +1,4 @@
trailingComma: "es5"
tabWidth: 2
semi: false
singleQuote: true

View File

@ -1,6 +1,6 @@
const Comment = require('./comment')
Comment.belongsTo(Comment, {as: 'parent'})
Comment.belongsToMany(Comment, {through: 'CommentReplies', as: { singular: 'reply', plural: 'replies' } })
Comment.belongsTo(Comment, { as: 'parent' })
Comment.hasMany(Comment, { as: { singular: 'reply', plural: 'replies' } })
module.exports = {Comment}
module.exports = { Comment }

View File

@ -4,9 +4,9 @@ const { Comment } = require('./models')
const tc1 = {text: 'c1'}
const tc2 = {text: 'c2'}
const tc3 = {text: 'c3'}
// const tc4 = {text: 'c4'}
// const tc5 = {text: 'c5'}
// const tc6 = {text: 'c6'}
const tc4 = {text: 'c4'}
const tc5 = {text: 'c5'}
const tc6 = {text: 'c6'}
async function runSeed() {
@ -17,15 +17,18 @@ async function runSeed() {
const c1 = await Comment.create(tc1)
const c2 = await Comment.create(tc2)
const c3 = await Comment.create(tc3)
// const c4 = await Comment.create(tc4)
// const c5 = await Comment.create(tc5)
// const c6 = await Comment.create(tc6)
const c4 = await Comment.create(tc4)
const c5 = await Comment.create(tc5)
const c6 = await Comment.create(tc6)
await c1.addReply(2)
await c2.setParent(1)
//await c2.setParent(1)
await c2.addReply(3)
await c3.setParent(2)
//await c3.setParent(2)
//await c4.setParent(2)
console.log('seeded successfully')
} catch (err) {