JKHeadley / JKHeadley/rest-hapi

Associations within subdocs?

Open
#102 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.2k
Forks
155
PR merge metrics
No merged PRs in 30d

Description

(This is more of a question than an issue, but it could turn into an issue.)

Is it possible, in rest-hapi, to have an association within a subdocument?

For example, I can do this in Mongoose, where the association is at `subdoc.pets`, instead of being at the top level of the document:

```
const ownerSchema = new Schema({
name: Schema.Types.String,
subdoc: {
pets: [{ type: Schema.Types.ObjectId, ref: 'pet' }],
},
});

Owner.findOne().populate('subdoc.pets');
```

If it were at the top level, I would implement this in rest-hapi by adding an association under routeOptions. I'm not sure how or if I can do this within a subdocument, however.

I don't actually need endpoints for this particular association; I just need to be able to populate it when requesting the document, if that makes a difference.

Thanks!

Contributor guide

Open the contributing guide

Research direction

Start with rest-hapi's routeOptions association configuration and the Mongoose schema/populate example in the issue. Check whether nested subdocument paths such as subdoc.pets can be represented and populated without endpoints. Done means a documented supported configuration or a clearly scoped implementation and test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
backend-api-design, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.