-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Description
I've got a One-to-One relationship between a User model and a few role models such as Admin, Manager, and Customer. How might you handle a scenario like this? I'm using Mongoose, but I believe the same principles apply for any One-to-One relationship.
User Schema
var UserSchema = new Schema({
email: {
// ...
},
password: {
// ...
},
roles: {
admin: { type: mongoose.Schema.Types.ObjectId, ref: 'Admin' },
manager: { type: mongoose.Schema.Types.ObjectId, ref: 'Manager' },
customer: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer' }
},
salt: {
// ...
},
updated: {
// ...
},
created: {
// ...
}
});Admin Schema
var AdminSchema = new Schema({
user: {
id: { type: Schema.Types.ObjectId, ref: 'User' },
name: { type: String, default: '' }
},
created: {
// ...
}
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels