Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot validate complex object (v0.9.1) #224

Closed
engenb opened this issue Apr 21, 2014 · 6 comments
Closed

cannot validate complex object (v0.9.1) #224

engenb opened this issue Apr 21, 2014 · 6 comments

Comments

@engenb
Copy link

engenb commented Apr 21, 2014

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.

@Dakuan
Copy link

Dakuan commented Aug 18, 2014

we are also bumping into this

@captDaylight
Copy link

Thirded, this is an issue for us too

@captDaylight
Copy link

here is the question I posted on stack http://jsfiddle.net/captDaylight/rkz1dxfw/2/

@kevynb
Copy link

kevynb commented Sep 1, 2014

I have the same problem too

@calweb
Copy link

calweb commented Dec 15, 2014

ran into this same issue today, trying to validate complex object. Is this issue still being looked at?

In our case, we're using preValidate, in which we're trying to validate a complext object.

@chiefGui
Copy link
Collaborator

Fixed by #260.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants