'Ember JS check if the model is already defined
Trying to define custom model in ember using
Ember.getOwner(this.store).register('model:custom-model', {
customName: DS.attr('string')
});
While running the same component again, getting the following error saying the model is already defined.
Uncaught (in promise) Error: Assertion Failed: Cannot re-register: 'model:custom-model', as it has already been resolved.
How to check if the model is already defined?
Solution 1:[1]
There is the hasRegistration() method which should help you, i.e.
if (Ember.getOwner(this.store).hasRegistration('model:custom-model')) {...}
One thing though - you're using quite old version of Ember, so this answer might require some refinement, however this method exists at least in v2.18.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrey Stukalin |
