我有关于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