Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
efbsolis opened this issue Jan 14, 2017 · 1 comment
Open

Comments

@efbsolis
Copy link

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant