Ember:异步有很多关系问题



我迷失在余烬数据承诺中,拥有更多关系。这是我所拥有的:

tarifs 和预留都在应用程序启动时加载(成功):

App.ApplicationRoute = Ember.Route.extend({
  model: function() {
    return Em.RSVP.hash({
      tarifs: this.store.find('tarif'),
      reservations: this.store.find('reservation')
    });
  }
});

然后,tarifsreservations 绑定为 spectacles

App.SpectaclesRoute = Ember.Route.extend({
  isLoaded:false,
  model: function() {
      if(this.isLoaded) {
          return this.store.all('spectacle');
      }
      this.isLoaded = true;
      return this.store.find('spectacle');
    }
});

服务器返回Spectacles具有representations ID 数组和tarifs ID 数组。 Representations对象在下面的同一响应中返回。 Tarifs已经在商店里了,这要归功于第一个电话。

这是Spectacle模型:

App.Spectacle = DS.Model.extend({
  titre: DS.attr('string'),
  sousTitre: DS.attr('string'),
  visuelUrl: DS.attr('string'),
  tarifs: DS.hasMany('tarif', { async: true }),
  representations: DS.hasMany('representation', { async: true })
});

问题是:从我所看到的(使用 ember 浏览器插件)来看,spectaclestarifs没有链接(而spectaclesrepresentations是)。我能找到的唯一区别是它们是在两个单独的服务器调用中加载的,但这应该不是问题,对吧?

我认为这可能是一个异步/承诺问题。我需要的是,从代表中,获得第一个奇观的塔里夫。简而言之:myRepresentation.spectacle.tarifs[0]。我尝试了各种方法,例如:

representation.get('spectacle.tarifs').then(function(tarifs) {
  var tarif = tarifs.get('firstObject');
  console.log(tarif);
}

没有任何工作:tarif始终为空。似乎所有记录都已加载,但spectacletarifs之间的关系没有。

我做错了什么吗?

好吧,算了,问题出在tarif模型中:

App.Tarif = DS.Model.extend({
  nom: DS.attr('string'),
  montant: DS.attr('number'),
  spectacle: DS.belongsTo('spectacle', { async: true })
});

"属于"关系是一个错误,因为tarif可以链接到许多spectacles。我刚刚删除了这一行,现在一切都很好。