问题描述
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.
推荐答案
嵌入式标志是过时的,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.
资料来源:
这是一个来自复杂模型的服务器响应示例。
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
这篇关于如何拥有与嵌入式关系的永恒关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!