Skip to content

MichaelErmer/feathers-populate-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

feathers-populate-hook

NPM

Feathers hook to populate multiple fields with one to many, many to one and many to many relations. (For m:m cascade the populate hooks on a linking service.)

Installation:

npm install feathers-populate-hook

Example setup:

 const populate = require('feathers-populate-hook');

 messageService.after({
   find: [
     populate({
       user: { // Destination key
         service: 'users', // Foreign service
         f_key: 'id',  // Foreign key
         one: true // Optional, if only one resolve object is wanted
       },
       comments: { // Destination key
         service: 'comments', // Foreign service
         f_key: 'message',  // Foreign key
         l_key: 'id',  // Local key
        },
       resolvedCategories: { // Destination key
         service: 'categories', // Foreign service
         f_key: 'id',  // Foreign key
         l_key: 'categories' // Local key, optional, if different then destination key
       },
        creator: { // Destination key
          service: 'users', // Foreign service
          f_key: 'email',  // Foreign key
          l_key: 'createdByEmail',
          one: true,
          query:  {  // defaults to {} but you can specify any other options here
            $select: ['name','profile_image']
          }
        }
     })
   ]
 })

Query options

Set query defaults for the internal service call, i.e. $select, $order

Block some populates from the client: set query.$populate to {dontPopulateField: 0}

Block all populates: set query.$populate to false

About

Feathers hook to populate multiple fields with m:1, 1:m or m:m relations.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •