fullstack-apollo-express-postgresql-boilerplate
fullstack-apollo-express-postgresql-boilerplate copied to clipboard
Make model association step more idiomatic
- use Object.values to get a more meaningful
model
var and associate it if it has an associate field.
Another variant, bit more "functional" :
Object.values(models)
.filter(model => typeof model.associate === 'function')
.forEach(model => model.associate(models));
@Sharlaan I also considered
Object.values(models)
.filter(model => model.associate)
.forEach(model => model.associate(models));
and
Object.values(models).forEach(model => model.associate && model.associate(models));
but I preferred my proposal as most understandable.
Thanks for the input! I will take this into account once I write a new version for the tutorial 🚀 Given that it will take some time, please leave your suggestions here on how to make it more idiomatic!