简体   繁体   中英

Does DS.FixtureAdapter has sideload support?

I'm using DS.FixtureAdapter and can't get related entries using DS.belongsTo

App.User = DS.Model.extend({
    login: DS.attr('string'),
    profile: DS.belongsTo('App.Profile')
});

App.Profile = DS.Model.extend({
    fullname: DS.attr('string'),
    address: DS.attr('string'),
    user: DS.belongsTo('App.User')
});

App.Router.map(function() {
    this.resource('user', { path: ':user_id' });
});

App.UserRoute = Ember.Route.extend({
  model: function(params) {
    return App.User.find(params.user_id)
  }
});

Is it only a feature of Rest Adapter?

update

The fixture data is something like this:

something like this:

App.User.FIXTURES = [
    {
      id: 1,
      login: "marlus",
      profile: 1
    }
];

App.Profile.FIXTURES = [
    {
      id: 1,
      fullname: "Marlus Araujo",
      address: "Rio",
      user: 1
    }
];

Try:

return this.get('store').find('App.User', params.user_id);

Also, this could be helpful: http://emberjs.com/guides/models/finding-a-record/

The latest version of Ember Data (1.0.0-beta4), has a new syntax for configuring a model with a fixture adapter.

App.UserAdapter = DS.FixtureAdapter.extend();

App.User.FIXTURES = [{
    id: 1, firstName: 'Bob', lastName: 'Roberts'
}];

App.UsersRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('user');
    }
});

App.UserRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('user', params.user_id);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM