Aliraza
Aliraza

Reputation: 84

Node sequelize not creating associations

I am unable to create associations with sequelize in nodejs, it's creaing only booking not creating Notes automatically.

here is my code

db.js

async function initialize() {   

   db.Booking = require('../bookings/booking.model')(sequelize);
   db.Note = require('../notes/note.model')(sequelize);

   db.Note.belongsTo( db.Booking );
   db.Booking.hasMany( db.Note );

}

booking.service.js

async function create(params) {
   const data = await db.Booking.create(params, { include: [{model: db.Note, as: 'Notes'}] }).then( async ( booking ) => {});
});

i am passing params like this

{
   "status": "Active",
   "oneTime": "0",
   "start": "2021-12-25",
   "end": "2021-12-25",
   "Notes": [
      {
          "text": "This an test",
          "private": 0
      }
   ]
}

Thanks in advance.

Upvotes: 0

Views: 98

Answers (1)

Aliraza
Aliraza

Reputation: 84

Notes Parameter was missing in validation schema, because if this sequelize was unable to get Notes data :P

Upvotes: 0

Related Questions