the-road-to-graphql / fullstack-apollo-express-postgresql-boilerplate

💥 A sophisticated GraphQL with Apollo, Express and PostgreSQL boilerplate project.
https://roadtoreact.com
MIT License
1.2k stars 265 forks source link

Make model association step more idiomatic #57

Open morenoh149 opened 5 years ago

morenoh149 commented 5 years ago
Sharlaan commented 5 years ago

Another variant, bit more "functional" :

  Object.values(models)
    .filter(model => typeof model.associate === 'function')
    .forEach(model => model.associate(models));
morenoh149 commented 5 years ago

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

rwieruch commented 5 years ago

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!