I'm confused if nested validation it's supported, how it works and if it's possible do the situation described below
I have the following models
Customer based on PersistedModelcontact property type ContactInfoaddress property type AddressContactInfo based on ModelemailAddress property type stringphoneNumber property type stringfirstName property type stringlastName property type stringAddress based on Modelstreet property type stringcity property type stringstate property type stringzipCode property type stringI also want to validate
contact.emailAddress is unique, but not requiredcontact.phoneNumber is unique, but not requiredI want know if it's possible validate only when it's present in the payload and using the default validators e.g. validatesUniquenessOf
Currently I've added a validator
//contact-info.js
module.exports = function(ContactInfo) {
ContactInfo.validatesUniquenessOf('phoneNumber', {message: 'You can\'t use this number', allowNull: true});
};
for testing proposes I have in my database a document in the Customer collection
{
"_id": ObjectId("56003b7901caa9db416eca5f"),
"contact": {
"firstName" "Bob",
"lastName" "SquarePants",
"phoneNumber": "555-5678"
}
}
and sent following request
POST /api/Customers
{
"contact": {
"firstName" "Patrick",
"lastName" "Star",
"phoneNumber": "555-5678"
}
}
the expected result is a 422 response but I get a 200, btw I think it should be a 201
I don't believe we support deep validation. See https://github.com/strongloop/loopback/issues/300#issuecomment-44973571
For future reference, please post questions to https://groups.google.com/forum/#!forum/loopbackjs. See https://github.com/strongloop/loopback/wiki/Questions for more details.
Has this been implemented in latest versions ? if not, are there are any future plans to implement this? Happy to pick this up if this is still an open feature
Has this been implemented in latest versions ? If yes, can you share link for documentation or examples.
Most helpful comment
Has this been implemented in latest versions ? If yes, can you share link for documentation or examples.