fullstack-apollo-express-postgresql-boilerplate icon indicating copy to clipboard operation
fullstack-apollo-express-postgresql-boilerplate copied to clipboard

Make model association step more idiomatic

Open morenoh149 opened this issue 5 years ago • 3 comments

  • use Object.values to get a more meaningful model var and associate it if it has an associate field.

morenoh149 avatar Mar 08 '19 23:03 morenoh149

Another variant, bit more "functional" :

  Object.values(models)
    .filter(model => typeof model.associate === 'function')
    .forEach(model => model.associate(models));

Sharlaan avatar Mar 09 '19 11:03 Sharlaan

@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.

morenoh149 avatar Mar 09 '19 22:03 morenoh149

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!

rwieruch avatar May 14 '19 09:05 rwieruch