如何拥有与嵌入式关系的永恒关系 [英] How to have hasOne relation with embedded always relation
问题描述
EmberJS已在之前的修订版中删除了hasOne。创建这样一个嵌套的对象关系的方式是什么我想要有一个
EmberJS has removed hasOne in the earlier revision. Whats the way to create such a nested object relation where I want to have hasOne
删除hasOne已经完成了有利于belongsTo,任何人都可以分享一下如何在嵌套的JSON中写入{embed:always}关系。
Removal of hasOne has been done in favor of belongsTo, can anyone share a thought on how to write {embedded : always} relation between nested JSON.
推荐答案
我知道这个问题是旧的并回答,但由于它是ember hasone的顶级
搜索结果之一,我想分享我的调查结果。
我已经阅读了第一个答案中的链接,但这个例子有点过时了。
I know that this question is old and answered, but since it is one of the top search results for "ember hasone" i wanted to share my findings on the subject. I've read the link in the first answer but the example is kinda outdated.
嵌入式标志是过时的,DS.RESTAdapter.map不是一个函数,并且不建议使用DS.hasOne方法。
The "embedded" flag is obsolete, "DS.RESTAdapter.map" is not a function and the "DS.hasOne" method deprecated.
目前用于模拟hasOne关系的1.0.0-beta.2解决方案只是使用DS.belongsTo。他们没有很大的不同,你只需要将hasOne外键添加到你的结果集中,就像你对belongsTo一样。
The current 1.0.0-beta.2 solution for emulating the "hasOne relationship" is simply using "DS.belongsTo". They are not very different and you just need to add the hasOne foreignKeys to your result-set just like you would with belongsTo.
资料来源: https://github.com/emberjs/data/commit/a466741a36731c5d382df33461268024627325ef
这是一个来自复杂模型的服务器响应示例。
Here's an example server response from a complex model.
{"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的信息
Hope this helps anyone looking for info on how to model a hasOne
这篇关于如何拥有与嵌入式关系的永恒关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!