Important: This is the documentation for a previous version of Feathers.
For the latest documentation please visit docs.feathersjs.com.
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 directory has changed:
The populateTeams hook
The generator has roughed out an after hook for the
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
populateTeams. We told the generator to create an
afterhook for the
findmethod, 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
populatehook 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.
The generated code, once again, contains no surprises for us as we have covered it before. Now we can run our application.