Skip to content

Instantly share code, notes, and snippets.

@Ivan-Feofanov
Last active October 17, 2024 11:52
Show Gist options
  • Select an option

  • Save Ivan-Feofanov/eefe489a2131f3ec43cfa3c7feb36490 to your computer and use it in GitHub Desktop.

Select an option

Save Ivan-Feofanov/eefe489a2131f3ec43cfa3c7feb36490 to your computer and use it in GitHub Desktop.
Get list of association methods of model in Sequelize
const model = %yourSequelizeModel%
for (let assoc of Object.keys(model.associations)) {
for (let accessor of Object.keys(model.associations[assoc].accessors)) {
console.log(model.name + '.' + model.associations[assoc].accessors[accessor]+'()');
}
}
@Ivan-Feofanov

Ivan-Feofanov commented Nov 19, 2017

Copy link
Copy Markdown
Author

Instead of %yourSequelizeModel% use your model

@heisian

heisian commented Mar 31, 2018

Copy link
Copy Markdown

this is awesome, thank you!

@deezone

deezone commented Mar 12, 2019

Copy link
Copy Markdown

Amazing! Very, very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment