DEV Community

Discussion on: A crash course on Serverless with AWS - Building APIs with Lambda and Aurora Serverless

Collapse
 
softnayr profile image
Ryed Ban • Edited

Hi Adnan,

Great work buddy!

I just got one question - how would you associate another model to the Note model?
Let's say we have a User model and we would like to implement Note.belongsTo(User).

I have made something like this but it keeps me getting an error like "note is not associated to user"

const User = require('./User');
module.exports = (sequelize, type) => {
const Note = sequelize.define('note', {
id: {
type: type.INTEGER,
primaryKey: true,
autoIncrement: true
},
title: type.STRING,
description: type.STRING
})

Note.associate = (models) => {
    Note.belongsTo(models.User, {
        foreignKey: 'user_id',
        as: user
    })
}

return Note
Enter fullscreen mode Exit fullscreen mode

}

Collapse
 
lilhamad profile image
Lilhamad Adewale

Hi @softnayr were you able to solve the "note is not associated to user" issue