restgen icon indicating copy to clipboard operation
restgen copied to clipboard

Related Records

Open alexferreira opened this issue 11 years ago • 0 comments

Support records related example:

userSchema var = new Schema ({
  name: String,
  email: String,
  posts: [{type: Number, ref: 'Post'}]
  comments: [{type: Number, ref: 'Person'}]
});

mongoose.model ('User', userSchema);

postSchema var = new Schema ({
  name: String,
  text: String,
  comments: [CommentSchema]
  created_by: {type: Schema.Types.ObjectId, ref: 'User'}
});

mongoose.model ('Post', postSchema);

commentSchema var = new Schema ({
  text: String,
  created_by: {type: Schema.Types.ObjectId, ref: 'User'},
  posted_by: {type: Schema.Types.ObjectId, ref: 'User'}
});

mongoose.model ('Comment', commentSchema);

URL request

http://localhost/users/51a5b6f075deff0000000002.json

return

{
    "_id": "51a5b6f075deff0000000002",
    "name": "Alex Ferreira",
    "email: "[email protected],
    "posts": [
      {
        name: "Title",
        text: "Text example",
        created_by: "51a5b6f075deff0000000002"
      }
    ],
    "comments": [
      {
        text: "Text example",
        created_by: "51a5b6f075deff0000000002",
        post_id: "51a3fe53317624726f000001",
      }
    ],

http://localhost/users/51a5b6f075deff0000000002/posts.json

return

[
  {
    "_id": "51a3fe53317624726f000001",
    "name": "Title",
    "text": "Text example",
    "created_by": "51a5b6f075deff0000000002",
    "comments": [
      {
        text: "Text example",
        created_by: "51a5b6f075deff0000000002",
        post_id: "51a3fe53317624726f000001",
      }
    ],
  }
]

http://localhost/users/51a5b6f075deff0000000002/comments.json

return

[
  {
    "_id": "51a5b4c341328d0000000002",
    "text": "Text example",
    "created_by": "51a5b6f075deff0000000002",
    "post_id": "51a3fe53317624726f000001",
  }
]

alexferreira avatar May 29 '13 08:05 alexferreira