Add the populate hook
When we obtain a teams record, we want to add the team's users to the team record. This requires a hook and therefore we generate the scaffolding for a hook using:
feathers generate hook
The generator will add some new modules and modify some existing ones. You can see all the changes here: Unified | Split
New modules
The directory has changed:
The populateTeams hook
The generator has roughed out an after hook for the teams
service.
This hook doesn't do anything so far, but its been placed in the structure and wired into the app.
This caused the following modules to be added:
src/hooks/populate-teams.js contains code for a hook that presently does nothing.
test/hooks/populate-teams.test.js tests that the hook is configured.
The hook had to be wired into the app, so the generator made the following changes:
- src/services/teams/teams.hooks.js now
(Unified
|
Split)
uses the
populateTeams
. We told the generator to create anafter
hook for thefind
method, and that is when it is being run.
ProTip: What you put in populate-teams.js is up to you. You'd likely use the
populate
hook for DB adapters other than Sequelize. You may decide to use the more performant internal populate features for Sequelize. The generator creates a hook which does nothing.
What's next?
The generated code, once again, contains no surprises for us as we have covered it before. Now we can run our application.