I have started working with EmberJS and Ember-Data, but I've run into a small problem.
I have an application where my data source uses a non-id as the primary key (e.g. /model/<slug_name>
). I am using the FixtureAdapter
to handle things until I connect it to the backend:
App.ApplicationAdapter = DS.FixtureAdapter.extend({})
App.MyModel = DS.Model.extend({
slug: DS.attr('string'),
body: DS.attr('string')
});
App.MyModel.FIXTURES = [{
slug: 'test-slug',
body: 'Body goes here'
}];
There seem to be several sources of information that explain how to use a different primary key, but they are all oriented around working with the actual data source (and involve modifying the serializer; something that isn't used when working with FixtureAdapter
).
If I do the naive thing and just wire up routes...
// ...
App.MyModelEditRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('mymodel', params.slug)
}
});
... and change the template...
{{#link-to "mymodel.edit" slug}}Edit{{/link-to}}
...then I get this error:
Assertion failed: You made a request for a mymodel with id test-slug, but the adapter's response did not have any data
How can I use a non-'id' field as the primary key when working with a FixtureAdapter
?
Ideally, is there a solution that works when using a FixtureAdapter
or a real data source?
For reference, these are the versions of EmberJS and Ember-Data that I am using:
"ember": "~1.3.2",
"ember-data": "~1.0.0-beta.8"