EmberJS 在早期版本中删除了 hasOne。在我想要 hasOne 的地方创建这样的嵌套对象关系的方法是什么
已经删除了 hasOne 以支持 ownTo,任何人都可以分享一下如何在嵌套 JSON 之间编写 {embedded : always} 关系的想法。
我知道这个问题很旧并且已经得到解答,但由于它是最重要的问题之一
“ember hasone”的搜索结果 我想分享我在这个主题上的发现。
我已阅读第一个答案中的链接,但该示例有点过时了。
“embedded”标志已过时,“DS.RESTAdapter.map”不是函数,并且“DS.hasOne”方法已弃用。
当前用于模拟“hasOne 关系”的 1.0.0-beta.2 解决方案只是使用“DS.belongsTo”。它们并没有太大不同,您只需将 hasOneforeignKeys 添加到结果集中,就像使用 ownTo 一样。
Source: https://github.com/emberjs/data/commit/a466741a36731c5d382df33461268024627325ef https://github.com/emberjs/data/commit/a466741a36731c5d382df33461268024627325ef
以下是复杂模型的服务器响应示例。
{"users": [{
"id": 1,
"name": "John Doe",
"profile": 27, // merged hasone
"image": 3, // merged hasone
"account_id": 64 // an actual belongsTo
}]}
然后作为模特
App.User = DS.Model.extend({
name: DS.attr('string'),
profile: DS.belongsTo('profile'),
image: DS.belongsTo('image'),
account_id: DS.belongsTo('account')
});
希望这可以帮助任何寻找有关如何建模 hasOne 的信息的人
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)