corvid
corvid

Reputation: 11187

divide Meteor.users into different schemas

I want to have different types of users for my web application. They would have all the methods of normal users, but different Schemas, specifically for settings and profile. Eg:

var UserBase = {
  emails: {
    type: [Object],
    optional: true
  },
  // ... etc not important
}

AdminSchema = new SimpleSchema(_.extend(UserBase, {
  profile: {
    type: AdminProfileSchema
  },
  settings: {
    type: AdminSettingsSchema
  }
}));

UserSchema = new SimpleSchema(_.extend(UserBase, { // yada yada });

// more or less what I want to do:
Meteor.users.attachSchema(AdminSchema, { role: "admin" });
Meteor.users.attachSchema(UserSchema, { role: "user"});

Is it possible to attach different schemas to Meteor.users, assuming no collisions?

Upvotes: 0

Views: 145

Answers (1)

Gaelan
Gaelan

Reputation: 1149

I would have the two schemas (user, admin) as sub-objects of the main user schema, equalling null if they aren't set, like this:

var UserSchema = {
  emails: {
    type: [Object],
    optional: true
  },
  // ... etc not important
  admin: {
    type: AdminSchema,
    optional: true
  },
  user: {
    type: UserSchema,
    optional: true
  }
}

Upvotes: 2

Related Questions