Closed DagemBefikadu closed 2 years ago
You need to create a coffee, not a usercoffee
(also, you want to do a findOrCreate, not create)
then after you've found or created, you can associate the coffee with the user
router.post('/:id', (req,res) => {
db.coffee.findOrCreate({
userId: res.locals.currentUser.id,
coffeeId: req.params.id
})
.then(favCoffee => {
console.log(favCoffee)
res.redirect('/profile')
})
.catch(error => {
console.log(error)
})
})
lmk how this goes
The error that i got:
TypeError: Cannot read property 'create' of undefined