环回:将model.settings.validateUpsert覆盖为false [英] Loopback: model.settings.validateUpsert was overriden to false
问题描述
我有一个使用MongoDB的回送应用程序,如下所示,但是我的问题是关于终端上的消息(不是错误),所以我的终端看起来像这样:
I have a loopback app with MongoDB as below, however my question is about a message on my terminal (not an error) so my terminal would look like this:
dishes settings.validateUpsert was overriden to false
Comments settings.validateUpsert was overriden to false
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
我的应用程序文件夹的路径....>节点.
The path to my app folder....> node .
如您所见,服务器运行时没有错误.该消息是什么意思?我设法通过将TimeStamp设置为false来避免这种情况:
As you can see that the server runs without an error. What is the meaning of that message? I managed to avoid it by setting TimeStamp to false like this:
"mixins": {
"TimeStamp": true // => change this to false.
}
但是我不相信这种解决方案.
but I'm not convinced with this solution.
这是我的模特:
dish.json:
dish.json:
{
"name": "dishes",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"description": {
"type": "string",
"required": true
},
"category": {
"type": "string",
"required": true
},
"image": {
"type": "string",
"required": true
},
"label": {
"type": "string",
"required": true,
"default": "''"
},
"price": {
"type": "string",
"required": true,
"default": "0"
}
},
"mixins": {
"TimeStamp": true
},
"validations": [],
"relations": {
"comments": {
"type": "hasMany",
"model": "Comments",
"foreignKey": ""
},
"customers": {
"type": "hasMany",
"model": "Customer",
"foreignKey": ""
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "create"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW"
}
],
"methods": {}
}
comments.json:
comments.json:
{
"name": "Comments",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"Rating": {
"type": "number",
"required": true,
"default": 5
},
"comment": {
"type": "string",
"required": true
}
},
"mixins": {
"TimeStamp": true
},
"validations": [],
"relations": {
"dishes": {
"type": "belongsTo",
"model": "dishes",
"foreignKey": ""
},
"customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "customerId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "create"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
"methods": {}
}
customer.json:
customer.json:
{
"name": "Customer",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"comments": {
"type": "hasMany",
"model": "Comments",
"foreignKey": "customerId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
}
],
"methods": {}
}
和script.js:
and script.js:
module.exports = function(app) {
var MongoDB = app.dataSources.MongoDB;
MongoDB.automigrate('Customer', function(err) {
if (err) throw (err);
var Customer = app.models.Customer;
Customer.create([
{username: 'Admin', email: 'admin@admin.com', password: 'abcdef'},
{username: 'muppala', email: 'muppala@ust.hk', password: 'abcdef'}
], function(err, users) {
if (err) throw (err);
var Role = app.models.Role;
var RoleMapping = app.models.RoleMapping;
Role.find({ name: 'admin' }, function(err, results) {
if (err) { throw err; }
if (results.length < 1) {
// now we know the DB doesn't have it already, so do the Role creation...
//create the admin role
Role.create({
name: 'admin'
}, function(err, role) {
if (err) throw (err);
//make admin
role.principals.create({
principalType: RoleMapping.USER,
principalId: users[0].id
}, function(err, principal) {
if (err) throw (err);
});
});
}
});
});
});
};
推荐答案
这是loopback-ds-timestamp-mixin
的要求.
请参见 https://github.com/clarkbw/loopback-ds-timestamp-mixin/blob/master/es6/time-stamp.js#L25 .
如果validateUpsert
是true
,则混合显示警告:
If validateUpsert
were true
, the mixin shows a warn:
当打开验证并需要时间戳时,ModelName的Upserts将失败"
"Upserts for ModelName will fail when validation is turned on and time stamps are required"
更新
要隐藏此警告,请按以下方式设置TimeStamp混合:
UPDATE
To hide this warns, set the TimeStamp mixin like this:
...
"mixins": {
"TimeStamp": {
"required" : false,
"validateUpsert": true,
"silenceWarnings": false
}
},
...
这篇关于环回:将model.settings.validateUpsert覆盖为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!