【问题标题】:Ember 'belongsTo' relationship not connecting 2 application modelsEmber 'belongsTo' 关系未连接 2 个应用程序模型
【发布时间】:2014-01-01 23:10:08
【问题描述】:

我有这个工作余烬片段: http://jsfiddle.net/wUC9w/

具有以下 2 种型号:

App.Card = DS.Model.extend
  title: DS.attr("string")
  description: DS.attr("string")
  template: DS.belongsTo("template", {async: true})

App.Template = DS.Model.extend
  title: DS.attr("string")
  cards: DS.hasMany("card", {async: true})

但是它拒绝在卡片视图中连接两个模型(它没有得到链接模板的标题)。我已经尝试在应用中使用 {async: true} 侧加载和预加载相关模板模型,但 ember 仍然无法将两者连接起来。

我查看了所有 ember 文档并在 IRC 中提出了很多帮助但没有运气, 任何意见将不胜感激!

【问题讨论】:

  • 解决了!在 belongsTo 关系上,fk 的 json 应该是 name_id(所以在这种情况下是 template_id)。供参考:[github.com/emberjs/data/blob/master/…
  • 只有在您使用活动模型序列化程序时才能这样做

标签: ember.js ember-data


【解决方案1】:

感谢 kingpin2k,

在 belongsTo 关系上,当使用活动模型序列化程序时,fk 的 json 应该是 name_id(因此在本例中为 template_id)。

供参考: https://github.com/emberjs/data/blob/master/TRANSITION.md#underscored-keys-_id-and-_ids

【讨论】:

  • 我不明白。我有同样的问题。你能发布你的代码吗?谢谢
  • 请注意 mockjax json 上的 _id 和 _ids 有很多和属于。
猜你喜欢
  • 2023-02-16
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-26
  • 2016-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多