Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make model association step more idiomatic #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

morenoh149
Copy link
Contributor

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

* use Object.values to get a more meaningful `model` var and associate it if it has an associate field.
@Sharlaan
Copy link

Sharlaan commented Mar 9, 2019

Another variant, bit more "functional" :

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

@morenoh149
Copy link
Contributor Author

morenoh149 commented Mar 9, 2019

@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
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants