我有關於Ember數據和Mongodb嵌入對象的問題。這裏是我的模型:emberdata和mongodb嵌入對象ID undefined
App.Contact = App.Entity.extend({
name : DS.attr('string'),
firstname : DS.attr('string'),
additional_names : DS.attr('string'),
civility : DS.attr('string'),
birthday : DS.attr('date'),
organization : DS.belongsTo('App.Organization'),
role : DS.attr('string'),
photo_source : DS.attr('string'),
photo_uri : DS.attr('string'),
gravatar_mail : DS.attr('string'),
addresses : DS.hasMany('App.Address', { embedded: true }),
emails : DS.hasMany('App.Email', { embedded: true }),
phones : DS.hasMany('App.Phone', { embedded: true })
});
現在我獲取通過API聯繫人:(GET /應用/ API/V1 /聯繫人/ 4f86c4774ab63c2417000001 /)這裏就是我得到:
{
"additional_names": null,
"addresses": [],
"birthday": null,
"civility": null,
"emails": [
{
"email": "[email protected]",
"label": null,
"resource_uri": "/app/api/v1/contact/4f86c4774ab63c2417000001/emails/0/",
"type": "HOME"
}
],
"firstname": "Alexandre",
"gravatar_mail": null,
"groups": [],
"id": "4f86c4774ab63c2417000001",
"name": "Simoui",
"organization": null,
"phones": [],
"photo_source": null,
"photo_uri": "/static/img/nophoto.png",
"resource_uri": "/app/api/v1/contact/4f86c4774ab63c2417000001/",
"role": null
}
我的「根「對象有一個ID,但嵌入對象」電子郵件「沒有。因爲在mongodb中,id不是在子文檔上設置的,而是僅在根文檔上設置的。
這種方式燼數據看到「電子郵件」對象沒有ID,然後它試圖通過API獲取完整的對象。例如:GET/app/api/v1/email/set // 404(NOT FOUND)
爲了確保這是wright問題,我嘗試用僞ID字段返回Mongodb子文檔。喜歡:(看郵件對象的差異)
{
"additional_names": null,
"addresses": [],
"birthday": null,
"civility": null,
"emails": [
{
"id": 431,
"email": "[email protected]",
"label": null,
"resource_uri": "/app/api/v1/contact/4f86c4774ab63c2417000001/emails/0/",
"type": "HOME"
}
],
"firstname": "Alexandre",
"gravatar_mail": null,
"groups": [],
"id": "4f86c4774ab63c2417000001",
"name": "Simoui",
"organization": null,
"phones": [],
"photo_source": null,
"photo_uri": "/static/img/nophoto.png",
"resource_uri": "/app/api/v1/contact/4f86c4774ab63c2417000001/",
"role": null
}
然後我沒有問題一切都很好。所以我的問題是:有沒有辦法解決它?
如果你已經解決了這個,你介意張貼你如何去了解它。 – brg 2012-08-17 11:52:33
你有沒有得到這個工作? – albertjan 2013-01-15 09:46:22
查看最新版本的ember-data,發生了很多變化。 Ember-data現在支持沒有ID的嵌入記錄。 – ThomasDurin 2013-01-15 12:47:51