Loopback validation on Properties who's types are other Models

心已入冬 提交于 2019-12-11 01:25:01

问题


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"
}

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.

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?

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


回答1:


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

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



来源:https://stackoverflow.com/questions/24161921/loopback-validation-on-properties-whos-types-are-other-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!