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

ember model validator breaks on ember-data 1.0.0-beta.19.1 #11

Closed sescobb27 closed 9 years ago

sescobb27 commented 9 years ago

in store.recordWasInvalid(this, errors); throws an error Uncaught TypeError: internalModel.adapterDidInvalidate is not a function.

reading the source code of ember-data I found this

// ===== InternalModel
// FOR USE DURING COMMIT PROCESS
/**
  @method adapterDidInvalidate
  @private
*/
adapterDidInvalidate: function (errors) {
  var recordErrors = this.getErrors();
  ember$data$lib$system$model$internal$model$$forEach.call(Ember.keys(errors), function (key) {
    recordErrors.add(key, errors[key]);
  });
  this._saveWasRejected();
}
// ===== InternalModel

/**
  This method is called once the promise returned by an
  adapter's `createRecord`, `updateRecord` or `deleteRecord`
  is rejected with a `DS.InvalidError`.
   @method recordWasInvalid
  @private
  @param {InternalModel} internalModel
  @param {Object} errors
*/
recordWasInvalid: function (internalModel, errors) {
  internalModel.adapterDidInvalidate(errors);
}

I think you should not call that method manually, instead make something like this: https://github.com/dockyard/ember-validations/blob/master/addon/validators/local/inclusion.js#L23

sescobb27 commented 9 years ago

https://github.com/emberjs/data/pull/3262 try to fix it for similar issue

esbanarango commented 9 years ago

@sescobb27 This PR by @davidstevens37 should solve this issue. (Thank you @davidstevens37 )

esbanarango commented 9 years ago

@sescobb27 Could you confirm it pls. Thank you!