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

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:

Compare gen3 and gen4 folders

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:

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 an after hook for the find 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.

Is anything wrong, unclear, missing?

Leave a comment.

results matching ""

    No results matching ""