【发布时间】:2014-08-29 19:06:53
【问题描述】:
我是 SailsJS(使用 v0.10)和 MongoDB 的新手,并试图实现用户/组关系的功能。我无法理解它。
这是我尝试实现的:
- 用户可以是一个或多个组的成员。
- 组可以有一个或多个成员(用户)。
- 组中的每个成员都可以有一个角色,Admin 或 Normal
- 在获取 User 时,还会将用户所属的所有 Groups 作为属性返回。
- 在获取 Group 时,还会将组中的所有 Users 作为属性返回。
我有以下模型。
User.js
module.exports = {
attributes: {
// Email, this is used as login credentials
email: {
type: 'email', // Email type will get validated by the ORM
required: true,
unique: true
},
// The name of the person, used to simplify identification
name: {
type: 'string',
required: true
},
}
};
Groups.js
module.exports = {
attributes: {
name: {
type: 'string',
required: true
},
description: {
type: 'string'
},
}
};
我需要一些关于如何实现它的帮助。
谢谢
【问题讨论】:
-
对于 mongodb 中的模式,请查看 these blog post 它是三个部分。我想他们会帮助你。
-
谢谢!重做它,并尝试从我得到的 ide 中制作一些原型。
标签: mongodb sails.js waterline