Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you handle references to other documents/tables? #16

Open
paynecodes opened this issue Aug 19, 2014 · 0 comments
Open

How do you handle references to other documents/tables? #16

paynecodes opened this issue Aug 19, 2014 · 0 comments

Comments

@paynecodes
Copy link

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: {
    // ...
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant