0.0.1 • Published 10 years ago

mongoose-v-etters v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

Mongoose-v-setters

Build Status Code Climate

Virtual setters and getters for references (eg. post_id for post)

Install

npm install mongoose-v-etters

Usage

var schema = mongoose.Schema({
  post: {type: ObjectId, ref: 'Post'}
});

vetters(schema, 'post');

var Comment = mongoose.model('Comment', schema);

Comment.create({post_id: post._id}, function(err, comment) {
  // comment.post    == post
  // comment.post_id == post._id
});

Chainable:

var schema = mongoose.Schema({
  post: {type: ObjectId, ref: 'Post'}
  author: {type: ObjectId, ref: 'Post'}
});

vetters(schema, 'post')
  .and('author');

var Comment = mongoose.model('Comment', schema);

Comment.create({post_id: post._id, author_id: author._id}, function(err, comment) {
  // comment.post      == post
  // comment.post_id   == post._id
  // comment.author    == author
  // comment.author_id == author._id
});

License

MIT