esbanarango / ember-model-validator

ember-cli addon adds validation support to your Ember-Data models.
http://esbanarango.github.io/ember-model-validator/
MIT License
166 stars 35 forks source link

not validate octane relations #209

Open wallacyalva opened 2 years ago

wallacyalva commented 2 years ago

validate my relation is presence but is not validate . i try validate a computed relation id is it working, probably it is check relation but is not checked a content of relation

  @belongsTo('city') city;
  @belongsTo('state') state;

  @computed('state') get state2() {
    return get(this,'state.id');
  }

  @computed('city') get city2() {
    return get(this,'city.id');
  }

validations = {
      city2:{
        presence: {
          message: "A cidade é necessária."
        },
      },
      state2:{
        presence: {
          message: "O estado é necessário."
        },
      },
      city:{
        presence: {
          message: "A cidade é necessária."
        },
      },
      state:{
        presence: {
           message: "O estado é necessário."
        },
      }
}
corrspt commented 1 year ago

I think I'm being bit by this as well. The relationship has a value but when ember-model-validator tries to get ${property}.content that comes out empty. Were you able to find a workaround @wallacyalva ? Thanks! I'm on ember/cli/data 3.28 with ember-model-validator 4.7

EDIT: After a few more rounds of research it seems I have a specific situation(?) the relations that aren't being validated have this particular validation definition:

presence: {
       message(_key: string, _value: string, model: any): string {
              return model.translate('generic.error.input-value');
       }
}

If I switch to a custom validation that checks something... it seems to work now :shrug: But this used to work fine in 3.X :)

EDIT2: After testing out my app I've found a instance of having only presence:true for a model and ember-model-validator telling me that the content does not exist (but it's there)