silvenon
silvenon

Reputation: 2197

How to have fixtures for certain models and REST for everything else?

I have an Ember app using an API which has most of the models implemented, but some of them not, and for those I would like to provide fixtures.

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'http://api.com'
});

App.Post = DS.Model.extend({
  title: DS.attr(),
  body: DS.attr(),
  author: DS.attr()
});

// ...

this.store.find('post', 1); // http://api.com/post/1

// ...

App.Tag = DS.Model.extend({
  hashtag: DS.attr(),
  color: DS.attr()
});

App.Tag.FIXTURES = [
  { hashtag: 'foo', color: '#000' },
  { hashtag: 'bar', color: '#fff' }
]

// ...

this.store.find('tag', 1) // searches among fixtures

Is this possible?

Upvotes: 0

Views: 96

Answers (2)

Greg Turner
Greg Turner

Reputation: 56

You can make adapters specific to models by doing this: App.TagAdapter = DS.FixtureAdapter.extend();

Upvotes: 2

MattDavies
MattDavies

Reputation: 87

How about using a different model with that particular route?

App.TagRoute = Ember.Route.extend({
    model: function() {
        return [
            { hashtag: 'foo', color: '#000' },
            { hashtag: 'bar', color: '#fff' }
        ];
    }
});

Upvotes: 1

Related Questions