简体   繁体   中英

How can i save Sails model without validation?

Is it possible to pass somethin to myModel.save() for pass validation.

Or, may be, exists special method for it? Somethin like myModel.saveWithoutValidation()

// MyModel.js
module.exports = {

    attributes: {
        title: {
            type: 'string',
            minLength: 3,
        },
    },

};

MyModel.findOne({
    id: 31830
}).exec(
    function (err, myRecord) {
        myRecord.title = 'a'; // it is too short

        myRecord.save(function (err, saved) {
            if (err) {
                console.log(err); // Error (E_VALIDATION)
            }
        });


    });

The short answer is that I don't know any way of passing in an argument that would override the validation.

The slightly longer answer is that you could remove the validation from attributes and do the validation yourself in two different model methods (eg myRecord.saveWithValidation(), myRecord.saveWithoutValidation().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM