if two models have two attributes with the same name, how can we get from the error validations object the modelName info for each attribute?
Environment
- Ember CLI Version: 2.11.1
- Ember CP Validations Version: 3.3.2
Steps to Reproduce
I have two models with has-many relationship, and both models have attributes with the same name (ex:- "title") .. when I get the "validation.errors" I get an array which contains two validation objects for both "title" of the first model and "title" of the second model .. the question is how can I get the modelName where each one of the "title"s belong to?
@NouranMahmoud any chance you can reproduce this in a twiddle so I can play around with it?
Sure @offirgolan thanks a lot for your help, I've created a full example of my case here I've added comments on the part that has the issue.
In a nutshell:
- The example contains main form (
multi-step-formcontroller) and two models (page,post). - Page and post have (
has-manyrelationship) and both have property "title" on their models. - I validate the form on "
goNext" action. - As this is a multi-step form so validation must be in specific fields (per step)
- validation on the first step won't pass because there is a "
title" property on "posts" model. -
Question: how can I know which
modeldoes thistitlebelong to? line:48, file:controllers/multi-step-form.js
@NouranMahmoud this seems to be a discovery issue on your end. I think think there is much I can do on the library side.
If I'm understanding this correctly, you have a page model with a hasMany of posts and you dont know which one is invalid.
You can do a couple of things here:
- Just do a quick look up to get the invalid ones
pageModel.get('posts').filterBy('validations.isInvalid'). That will return all invalid post models that belong to that page model. - You can restructure your logic. Im not really sure whats going on in your twiddle since it's a bit involved but if you're creating a new
pageobject, step 1 should have an empty postshasMany. - You can disable the hasMany validations on step one, and then re-enable it on step two. See the docs on the
disabledoption.
@NouranMahmoud the issue is quite old. Did you manage to solve your problem? Can we close the issue?