function legacyPopulate(target, options) {
	  options = Object.assign({}, options);

	  console.error('Calling populate(target, options) is now DEPRECATED and will be removed in the future. ' + 'Refer to docs.feathersjs.com for more information. (legacyPopulate)');

	  if (!options.service) {
	    throw new Error('You need to provide a service. (populate)');
	  }

	  var field = options.field || target;

	  return function (hook) {
	    function populate1(item) {
	      if (!item[field]) {
	        return Promise.resolve(item);
	      }

	      // Find by the field value by default or a custom query
	      var id = item[field];

	      // If it's a mongoose model then
	      if (typeof item.toObject === 'function') {
	        item = item.toObject(options);
	      }
	      // If it's a Sequelize model
	      else if (typeof item.toJSON === 'function') {
	          item = item.toJSON(options);
	        }
	      // Remove any query from params as it's not related
	      var params = Object.assign({}, hook.params, { query: undefined });
	      // If the relationship is an array of ids, fetch and resolve an object for each,
	      // otherwise just fetch the object.
	      var promise = Array.isArray(id) ? Promise.all(id.map(function (objectID) {
	        return hook.app.service(options.service).get(objectID, params);
	      })) : hook.app.service(options.service).get(id, params);
	      return promise.then(function (relatedItem) {
	        if (relatedItem) {
	          item[target] = relatedItem;
	        }
	        return item;
	      });
	    }

	    if (hook.type !== 'after') {
	      throw new errors.GeneralError('Can not populate on before hook. (populate)');
	    }

	    var isPaginated = hook.method === 'find' && hook.result.data;
	    var data = isPaginated ? hook.result.data : hook.result;

	    if (Array.isArray(data)) {
	      return Promise.all(data.map(populate1)).then(function (results) {
	        if (isPaginated) {
	          hook.result.data = results;
	        } else {
	          hook.result = results;
	        }

	        return hook;
	      });
	    }

	    // Handle single objects.
	    return populate1(hook.result).then(function (item) {
	      hook.result = item;
	      return hook;
	    });
	  };
	}
/**
	 * The populate hook uses a property from the result (or every item if it is a list)
	 * to retrieve a single related object from a service and add it to the original object.
	 * It is meant to be used as an after hook on any service method.
	 *
	 * @param {string} target - The prop name to contain the populated item or array of populated items.
	 *    This is also the default for options.field if that is not specified.
	 * @param {Object} options - options
	 *    For a mongoose model, these are the options for item.toObject().
	 *    For a Sequelize model, these are the options for item.toJSON().
	 * @param {string} options.service - The service for the related object, e.g. '/messages'.
	 * @param {string|Array.<string>} options.field - The field containing the key(s)
	 *    for the item(s) in options.service.
	 * @returns {Function} hook function(hook):Promise resolving to the hook.
	 *
	 * 'options.field' is the foreign key for one related item in options.service, i.e. item[options.field] === foreignItem[idField].
	 * 'target' is set to this related item once it is read successfully.
	 *
	 * If 'options.field' is not present in the hook result item, the hook is ignored.
	 *
	 * So if the hook result has the message item
	 *    { _id: '1...1', senderId: 'a...a', text: 'Jane, are you there?' }
	 * and the /users service has the item
	 *    { _id: 'a...a', name: 'John Doe'}
	 * and then the hook is run
	 *    hooks.populate('sender', { field: 'userId', service: '/users' })
	 * the hook result will contain
	 *    { _id: '1...1', senderId : 'a...a', text: 'Jane, are you there?',
	 *      sender: { _id: 'a...a', name: 'John Doe'} }
	 *
	 * If 'senderId' is an array of keys, then 'sender' will be an array of populated items.
	 */
The populate hook uses a property from the result (or every item if it is a list)
to retrieve a single related object from a service and add it to the original object.
It is meant to be used as an after hook on any service method.

@param {string} target - The prop name to contain the populated item or array of populated items.
This is also the default for options.field if that is not specified.
@param {Object} options - options
For a mongoose model, these are the options for item.toObject().
For a Sequelize model, these are the options for item.toJSON().
@param {string} options.service - The service for the related object, e.g. '/messages'.



If 'options.field' is not present in the hook result item, the hook is ignored.



If 'senderId' is an array of keys, then 'sender' will be an array of populated items.
The populate hook uses a property from the result ( or every item if it is a list ) to retrieve a single related object from a service and add it to the original object . It is meant to be used as an after hook on any service method . @param { string } target - The prop name to contain the populated item or array of populated items . This is also the default for options . field if that is not specified . @param { Object } options - options For a mongoose model these are the options for item . toObject () . For a Sequelize model these are the options for item . toJSON () . @param { string } options . service - The service for the related object e . g . ' / messages ' . If ' options . field ' is not present in the hook result item the hook is ignored . If ' senderId ' is an array of keys then ' sender ' will be an array of populated items .
function legacyPopulate(target, options) {
	  options = Object.assign({}, options);
	  console.error('Calling populate(target, options) is now DEPRECATED and will be removed in the future. ' + 'Refer to docs.feathersjs.com for more information. (legacyPopulate)');
	  if (!options.service) {
	    throw new Error('You need to provide a service. (populate)');
	  }
	  var field = options.field || target;
	  return function (hook) {
	    function populate1(item) {
	      if (!item[field]) {
	        return Promise.resolve(item);
	      }
	      var id = item[field];
	      if (typeof item.toObject === 'function') {
	        item = item.toObject(options);
	      }
	      else if (typeof item.toJSON === 'function') {
	          item = item.toJSON(options);
	        }
	      var params = Object.assign({}, hook.params, { query: undefined });
	      var promise = Array.isArray(id) ? Promise.all(id.map(function (objectID) {
	        return hook.app.service(options.service).get(objectID, params);
	      })) : hook.app.service(options.service).get(id, params);
	      return promise.then(function (relatedItem) {
	        if (relatedItem) {
	          item[target] = relatedItem;
	        }
	        return item;
	      });
	    }
	    if (hook.type !== 'after') {
	      throw new errors.GeneralError('Can not populate on before hook. (populate)');
	    }
	    var isPaginated = hook.method === 'find' && hook.result.data;
	    var data = isPaginated ? hook.result.data : hook.result;
	    if (Array.isArray(data)) {
	      return Promise.all(data.map(populate1)).then(function (results) {
	        if (isPaginated) {
	          hook.result.data = results;
	        } else {
	          hook.result = results;
	        }
	        return hook;
	      });
	    }
	    return populate1(hook.result).then(function (item) {
	      hook.result = item;
	      return hook;
	    });
	  };
	}
function legacyPopulate ( target , options ) { options = Object . assign ( { } , options ) ; console . error ( 'Calling populate(target, options) is now DEPRECATED and will be removed in the future. ' + 'Refer to docs.feathersjs.com for more information. (legacyPopulate)' ) ; if ( ! options . service ) { throw new Error ( 'You need to provide a service. (populate)' ) ; } var field = options . field || target ; return function ( hook ) { function populate1 ( item ) { if ( ! item [ field ] ) { return Promise . resolve ( item ) ; } var id = item [ field ] ; if ( typeof item . toObject === 'function' ) { item = item . toObject ( options ) ; } else if ( typeof item . toJSON === 'function' ) { item = item . toJSON ( options ) ; } var params = Object . assign ( { } , hook . params , { query : undefined } ) ; var promise = Array . isArray ( id ) ? Promise . all ( id . map ( function ( objectID ) { return hook . app . service ( options . service ) . get ( objectID , params ) ; } ) ) : hook . app . service ( options . service ) . get ( id , params ) ; return promise . then ( function ( relatedItem ) { if ( relatedItem ) { item [ target ] = relatedItem ; } return item ; } ) ; } if ( hook . type !== 'after' ) { throw new errors . GeneralError ( 'Can not populate on before hook. (populate)' ) ; } var isPaginated = hook . method === 'find' && hook . result . data ; var data = isPaginated ? hook . result . data : hook . result ; if ( Array . isArray ( data ) ) { return Promise . all ( data . map ( populate1 ) ) . then ( function ( results ) { if ( isPaginated ) { hook . result . data = results ; } else { hook . result = results ; } return hook ; } ) ; } return populate1 ( hook . result ) . then ( function ( item ) { hook . result = item ; return hook ; } ) ; } ; }
The populate hook uses a property from the result (or every item if it is a list)
 to retrieve a single related object from a service and add it to the original object.
The populate hook uses a property from the result ( or every item if it is a list ) to retrieve a single related object from a service and add it to the original object .
// Find by the field value by default or a custom query // If it's a mongoose model then // If it's a Sequelize model // Remove any query from params as it's not related // If the relationship is an array of ids, fetch and resolve an object for each, // otherwise just fetch the object. // Handle single objects.