Skip to content

Collection validation with deep: true Errors #4

@dfliess

Description

@dfliess

I think it would be usefull to get child errors when a collection is invalid and you call the validate method with deep option enabled.
I think this code solve this. if you think it's usefull you may use it / modify it / do what ever you want :D

@backbone-schema.js:1457
/**
 * Validates the collections models
 * @param  {Object=} options
 * @return {Array}  Returns an empty array or an array of errors
 * @private
 */
_validateModels: function(options) {
    var errors = [];

    options = options || {};
    if (options.expandErrors) {
        _.each(this.models, function(model) {
                    errors.push.apply(errors,model.validate(undefined,options));
                });
    } else {

        if(_.any(this.models, function(model) {
            return !model.isValid(undefined, options);
        })) {
            errors.push({
                level: 'error',
                rule: 'relation',
                message: '%(title) is invalid',
                values: {
                    'title': this.schema.title
                }
            });
        }
    }
    return errors;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions