如何使用MongoDB处理SailsJS中的用户/组关系?
我不熟悉使用v0.10和MongoDB的SailsJS,并且尝试实现用户/组关系的功能。我的脑袋绕不过去 这就是我试图实现的: 用户可以是一个或多个组的成员。 一个组可以有一个或多个用户成员。 组中的每个成员都可以有一个角色,管理员或普通角色 获取用户时,还将用户所属的所有组作为属性返回。 获取组时,还可以将组中的所有用户作为属性返回。 我有以下模型 User.js Groups.js 我需要一些帮助来实现这一点如何使用MongoDB处理SailsJS中的用户/组关系?,mongodb,sails.js,waterline,Mongodb,Sails.js,Waterline,我不熟悉使用v0.10和MongoDB的SailsJS,并且尝试实现用户/组关系的功能。我的脑袋绕不过去 这就是我试图实现的: 用户可以是一个或多个组的成员。 一个组可以有一个或多个用户成员。 组中的每个成员都可以有一个角色,管理员或普通角色 获取用户时,还将用户所属的所有组作为属性返回。 获取组时,还可以将组中的所有用户作为属性返回。 我有以下模型 User.js Groups.js 我需要一些帮助来实现这一点 谢谢您可以使用帆船/水线中的多对多关联来实现这一点。有关更多信息,请参阅: Use
谢谢您可以使用帆船/水线中的多对多关联来实现这一点。有关更多信息,请参阅: User.js Groups.js
对于mongodb中的模式,请看一下它的三个部分。我想他们会帮助你的。谢谢!让reda开发它,并尝试从我得到的IDE中创建原型。这并不能一直起作用,因为我无法使用此技术指定每个用户在组中的角色。
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
},
}
};
module.exports = {
attributes: {
name: {
type: 'string',
required: true
},
description: {
type: 'string'
},
}
};
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
groups: {
collection: 'groups',
via: 'members'
}
}
};
module.exports = {
attributes: {
name: {
type: 'string',
required: true
},
description: {
type: 'string'
},
// Members
members: {
collection: 'user',
via: 'groups'
}
}
};