对类型为其他模型的属性进行环回验证 [英] Loopback validation on Properties who's types are other Models

查看:38
本文介绍了对类型为其他模型的属性进行环回验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了两个模型;位置和地址,定义如下:

I have two Models defined; Location and Address, defined as follows:

"address": {
    "properties": {
        "address1": {
            "type": "string",
            "required": true
        }
    },
    "public": true,
    "dataSource": "db",
    "plural": "addresses"
},  
"location": {
    "properties": {
        "title": {
            "type": "string"
        },
        "address":{
            "type": "address",
            "required": true
        }
    },
    "public": true,
    "dataSource": "db",
    "plural": "locations"
}

当我通过API资源管理器基于 address 模型创建对象时, address1 上的 required 约束的行为符合预期,我必须提供一个值来创建对象.

When I Create an object based on the address Model via the API Explorer, the required constraint on address1 behaves as expected and I must supply a value to create the object.

当我通过API资源管理器基于 location 模型创建对象时,地址上的 required 约束按预期工作,但是地址模型的 address1 上的必需约束没有.我可以创建一个没有address1的地址,这不是我期望的.

When I Create an object based on the location Model via the API Explorer, the required constraint on the address works as expected, but the required constraint on the address1 of the address Model does not. I am able to create an address without an address1, which is not what I would expect.

我做错了还是仅对根对象执行验证?

Am I doing something wrong or is validation only performed on the root object?

我正在使用内存数据源,节点v0.10.24和回送v1.8.6.

I am using a memory datasource, node v0.10.24 and loopback v1.8.6.

推荐答案

目前,验证仅在根级别进行.您可以在 https://github.com/strongloop/loopback-datasource-juggler?

At this moment, validations only happen at root level. Can you open an issue at https://github.com/strongloop/loopback-datasource-juggler?

顺便说一句,我建议您将问题发布到 https://groups.google.com/论坛/#!forum/loopbackjs 以获得快速响应.

BTW, I recommend you post questions to https://groups.google.com/forum/#!forum/loopbackjs for prompt responses.

这篇关于对类型为其他模型的属性进行环回验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆