updated relation to one-to-many
This commit is contained in:
parent
bd5a7ef113
commit
31087e4be5
4
.prettierrc
Normal file
4
.prettierrc
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
trailingComma: "es5"
|
||||||
|
tabWidth: 2
|
||||||
|
semi: false
|
||||||
|
singleQuote: true
|
@ -1,6 +1,6 @@
|
|||||||
const Comment = require('./comment')
|
const Comment = require('./comment')
|
||||||
|
|
||||||
Comment.belongsTo(Comment, {as: 'parent'})
|
Comment.belongsTo(Comment, { as: 'parent' })
|
||||||
Comment.belongsToMany(Comment, {through: 'CommentReplies', as: { singular: 'reply', plural: 'replies' } })
|
Comment.hasMany(Comment, { as: { singular: 'reply', plural: 'replies' } })
|
||||||
|
|
||||||
module.exports = {Comment}
|
module.exports = { Comment }
|
||||||
|
19
db/seed.js
19
db/seed.js
@ -4,9 +4,9 @@ const { Comment } = require('./models')
|
|||||||
const tc1 = {text: 'c1'}
|
const tc1 = {text: 'c1'}
|
||||||
const tc2 = {text: 'c2'}
|
const tc2 = {text: 'c2'}
|
||||||
const tc3 = {text: 'c3'}
|
const tc3 = {text: 'c3'}
|
||||||
// const tc4 = {text: 'c4'}
|
const tc4 = {text: 'c4'}
|
||||||
// const tc5 = {text: 'c5'}
|
const tc5 = {text: 'c5'}
|
||||||
// const tc6 = {text: 'c6'}
|
const tc6 = {text: 'c6'}
|
||||||
|
|
||||||
|
|
||||||
async function runSeed() {
|
async function runSeed() {
|
||||||
@ -17,15 +17,18 @@ async function runSeed() {
|
|||||||
const c1 = await Comment.create(tc1)
|
const c1 = await Comment.create(tc1)
|
||||||
const c2 = await Comment.create(tc2)
|
const c2 = await Comment.create(tc2)
|
||||||
const c3 = await Comment.create(tc3)
|
const c3 = await Comment.create(tc3)
|
||||||
// const c4 = await Comment.create(tc4)
|
const c4 = await Comment.create(tc4)
|
||||||
// const c5 = await Comment.create(tc5)
|
const c5 = await Comment.create(tc5)
|
||||||
// const c6 = await Comment.create(tc6)
|
const c6 = await Comment.create(tc6)
|
||||||
|
|
||||||
await c1.addReply(2)
|
await c1.addReply(2)
|
||||||
await c2.setParent(1)
|
//await c2.setParent(1)
|
||||||
|
|
||||||
await c2.addReply(3)
|
await c2.addReply(3)
|
||||||
await c3.setParent(2)
|
//await c3.setParent(2)
|
||||||
|
//await c4.setParent(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log('seeded successfully')
|
console.log('seeded successfully')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user