resourcejs icon indicating copy to clipboard operation
resourcejs copied to clipboard

Can nested resources be created from a schema and its subdocument?

Open efbsolis opened this issue 9 years ago • 1 comments

When looking at the example code for the Nested Resources section, PARENT and CHILD refer to two Mongoose objects that handle two separate MongoDB collections. I confirmed this when running the code, as an empty Child collection was created in my database.

However, would there be a way to nest resources, using instead a document + subdocument like the following?

parent {
  parentId: xxx,
  parentName: "yyy",

  child: [
    {
    childId: zzz,
    childName: "aaa"
    },
  ],

}

With something along these lines defining their relationship in Mongoose:

var ChildSchema = new mongoose.Schema({
    // variables + id
});

var ParentSchema = new mongoose.Schema({
  // parent variables, id
  child: [ChildSchema]
});

In other words, I'd like to know if the parent and child REST interfaces can be defined with Resource() so that they refer to the main document and its nested contents.

Thanks for reading!

efbsolis avatar Jan 14 '17 17:01 efbsolis

Update: This could be chalked up to my relative inexperience with this library, so I posted the following question on Stack Overflow, where I try to break down the results I experience trying to implement the concept I describe above:

ResourceJS: Creating nested resources from Mongoose Schema + its child Schema?

efbsolis avatar Jan 14 '17 22:01 efbsolis