2015-04-20 44 views
0

我想爲我的Web應用程序擁有不同類型的用戶。他們將擁有普通用戶的所有方法,但具有不同的架構,特別是針對settingsprofile。例如:將Meteor.users劃分爲不同的模式

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"}); 

是否有可能將不同的架構附加到Meteor.users,假設沒有衝突?

回答

2

我將有兩個模式(用戶,管理員)爲主要用戶架構的子對象,等於空,如果他們沒有被設置,像這樣:

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

我也將指向流星-roles軟件包,如果你不知道它:https://github.com/alanning/meteor-roles有很好的內置角色功能,適用於鐵路由器和其他人。 – Jon

+0

我剛剛通過添加一些驗證來完成它,檢查數據類型不能設置,除非他們有問題的角色,這很好,所以接受 – corvid