-
Notifications
You must be signed in to change notification settings - Fork 156
Description
Hello there,
I am building an ember-cli project (well actually an ember-addon) using ember-model and have been having some troubles making it work with the ES6 module system provided by ember-cli.
TL;DR : Retrieving a model through the store does not correctly set the adapter and url attributes. Reopening the model class and setting the attributes solves it. But if you actually
importthe model in your router (for instance) and retrieve the model by this way, the adapter and url are actually set. Why ?
What precisely happens is :
// Route
import Ember from "ember";
export default Ember.Route.extend({
model: function() {
return this.get('store').modelFor('myModel').find(2);
},
setupController: function(controller, model) {
controller.set('model', model);
}
}); // Model
import Ember from "ember";
var Model = Ember.Model.extend();
Model.url = '/model/url';
Model.adapter = Ember.RESTAdapter.create();
export default Model; I get an Ember.Adapter must implement find Error: Ember.Adapter must implement find.
I have checked and it seems that this.store.modelFor('replay') correctly returns the model but without the attributes url and adapter set. Thus we get the default adapter (which only implements the interface) and an undefined URL.
It can be fixed by doing the following :
// Model
import Ember from "ember";
var Model = Ember.Model.extend();
Model.reopenClass({
url: '/model/url',
adapter: Ember.RESTAdapter.create()
});
export default Model; But I don't understand what causes it.
Furthermore, if I don't use the store to retrieve the model ( this.store.modelFor('replay') ) but instead import the model file :
// Route
import Ember from "ember";
import MyModel from "../../models/my-model";
export default Ember.Route.extend({
model: function() {
return MyModel.find(2); // Or something like that
}
});
It properly works and has the attributes set without needing to reopen the class.
BUT the container is actually not set for the models that are not retrieved through the store, and it then fails when fetching relations and other stuffs.
I have been having a lot of trouble with all this. I am totaly new to Ember and if someone has an explanation on why, how, I'd be delighted and could maybe provide a fix as seen fit : )
Have a good day !