Skip to content

cannot validate complex object (v0.9.1) #224

Closed
@engenb

Description

@engenb

per the documentation:
"Validating complex objects is also supported. To configure validation rules for objects, use dot notation in the name of the attribute, e.g 'address.street'."

with this approach, validation is failing. I think it's because of the code below from validate
allAttrs = _.extend({}, validatedAttrs, model.attributes, attrs),

this effectively combines the validatedAttrs hash with the model attributes which results in allAttrs looking something like this (pretending we're validating the street of a person's address):
person : { attributes : { address : { attributes : { street : '1234' } } }, address.street : undefined }

later on, when this is validated, flatten will determine the attributes hash already has a property address.street and will not properly flatten out the address object. If I remove validatedAttrs from the aforementioned _.extend(...) the issue is resolved, however I don't know if this will negatively impact anything else during validation.

I think if the structure was flattened first in a smart way using the validatedAttrs and THEN validatedAttrs was extended onto the resulting flattened structure to detect missing attrs, we'll be in good shape.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions