我有两个风帆模型
1. User_type
2. User
User_type型号:
module.exports = {
schema: true,
connection: 'mongo',
attributes: {
user_type: {
type: 'string',
required: true,
enum: ['superadmin', 'admin', 'follower']
},
toJSON() {
return this.toObject();
}
},
beforeUpdate: (values, next) => next(),
beforeCreate: (values, next) => next()
};
用户模型:
module.exports = {
schema: true,
attributes: {
fname: {
type: 'string',
required: true,
},
user_login_type: {
// This user_login_type should be having values from
// User_type Model with a reference to field 'user_type', that is
// whatever values(superadmin', 'admin', 'follower') are in the
// 'user_type' of collection(or model) 'User_type' should only be
// allowed to enter here, and no else value
},
toJSON() {
return this.toObject();
}
},
beforeUpdate: (values, next) => next(),
beforeCreate: (values, next) => next()
};
我提到了不同的文档,问题和答案,但我没有得到确切的流程,如何在帆中这样做
每一个帮助都非常明显
答案 0 :(得分:1)
看看associations。您可以使用model
属性创建引用:
...
user_login_type: {
model: 'User_type'
},
...
如果您想强制使用required: true
,请添加user_login_type
。
请注意,'superadmin'
的值不会是'admin'
,'follower'
,int newCenterY = getHeight() * 3 / 5;
之一,而是对相关模型的引用。