Last active
January 17, 2016 15:39
-
-
Save dprea/bd7a444d3019ecf55ed0 to your computer and use it in GitHub Desktop.
MEAN.js 0.4.2 - Mongoose.js Discriminator Schemas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Module dependencies. | |
*/ | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
/** | |
* Article Schema | |
*/ | |
// options creates the keys for each schema | |
var options = { discriminatorKey: 'kind' }; | |
var ArticleSchema = new Schema({ | |
created: { | |
type: Date, | |
default: Date.now | |
}, | |
title: { | |
type: String, | |
default: '', | |
trim: true, | |
required: 'Title cannot be blank' | |
}, | |
content: { | |
type: String, | |
default: '', | |
trim: true | |
}, | |
user: { | |
type: Schema.ObjectId, | |
ref: 'User' | |
} | |
}, options); | |
var Article = mongoose.model('Article', ArticleSchema); | |
// Special Article Schema | |
// USAGE: modules/articles/server/controllers/article.server.controller.js | |
// USAGE: In Dependencies: SpecialArticle = mongoose.model('SpecialArticle'), | |
var SpecialArticleSchema = new Schema({ | |
specialreason: { | |
type: String, | |
default: 'Its SPECIAL!' | |
} | |
}, | |
options); | |
var SpecialArticle = Article.discriminator('SpecialArticle', SpecialArticleSchema); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment