sequelize special methods code example
Example: sequelize special methods
const foo = await Foo.create({ name: 'the-foo' });
const bar1 = await Bar.create({ name: 'some-bar' });
const bar2 = await Bar.create({ name: 'another-bar' });
console.log(await foo.getBar());
await foo.setBar(bar1);
console.log((await foo.getBar()).name);
await foo.createBar({ name: 'yet-another-bar' });
const newlyAssociatedBar = await foo.getBar();
console.log(newlyAssociatedBar.name);
await foo.setBar(null);
console.log(await foo.getBar());