Repository navigation
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 !
Activity
[-]Ember-cli, retrieving a record from the store does not set adapter and url properties[/-][+]Ember-cli, retrieving a model from the store does not set adapter and url properties[/+]williscool commentedon May 9, 2015
I think this is happening to me as well.
In my case its a model that was copying into an app from an addon.
But ember just complains about Fixtures not being set for the model
danii1 commentedon May 14, 2015
There are many quirks with Ember Model in Ember Cli, furthermore:
Model.find(paramsHash)doesn't cache records in the store, whilethis.store.find('model', paramsHash)works as expected and records are being pushed to the store.spectras commentedon Oct 2, 2015
Doing this solves the issues with adapter for me:
But that's no permanent solution. A better way would be to inject the adapter in ember-model.