Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Populate hook with array of one ref return object not an array. #174

Closed
ducnvhn opened this issue Oct 24, 2017 · 1 comment
Closed

Populate hook with array of one ref return object not an array. #174

ducnvhn opened this issue Oct 24, 2017 · 1 comment

Comments

@ducnvhn
Copy link

ducnvhn commented Oct 24, 2017

Steps to reproduce

Here is my post schema in mongodb :

...
comments: [ {type: Schema.Types.ObjectId, ref: 'Comment'}]  //array of ref to comment
...

and the populate schema in the feather hook

const populateCommentSchema = {
 include: [
   service: 'comments',
   nameAs: 'comments',
   parentField: 'comments',   //the field in the Post schema
   childField: '_id'    //the field in the Comment schema
 ]
};

The post hook object:

const postHooks = {
  .....
  after: {
    ...
    find: [populate({ schema: populateCommentSchema  })]
    ...
  }
}

Expected behavior

when I try to populate Comments when calling find service method , the result should contain an array of Comments.

Actual behavior

But if the Post have just one ref of Comment in the array, the result of comments is just one object.

Did I made the wrong populate schema ? or something I missed along the way ? Please point me out.
Thank you very much.

@daffl
Copy link
Member

daffl commented Oct 24, 2017

@daffl daffl closed this as completed Oct 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants