我正在使用ember rc3和ember-data 12(sha e324f0e)(基本上是指南中推荐的文件)。我有两个模型设置如下:
App.User = DS.Model.extend({
username: DS.attr('string'),
playerType: DS.attr('string'),
cars: DS.hasMany('App.Car')
})
App.Car = DS.Model.extend({
name: DS.attr('string'),
thumb: DS.attr('string'),
user: DS.belongsTo('App.User')
})
返回的json是
{
"cars": [
{
"id": "50ace47234fa7557403e7f02",
"name": "Dodge Charger SRT8",
"thumb": "/static/images/carthumbs/18331.png",
"user_id": "502a754b34fa75280c000a7e"
},
{
"id": "508668cc34fa753b78784ca2",
"name": "BMW M3 Coup\u00e9",
"thumb": "/static/images/carthumbs/23250.png",
"user_id": "502a754b34fa75280c000a7e"
},
{
"id": "50c7545334fa750ab8cb3ac2",
"name": "BMW Z4 M Coup\u00e9",
"thumb": "/static/images/carthumbs/7618.png",
"user_id": "502a754b34fa75280c000a7e"
},
{
"id": "50adf64c34fa750bb036121e",
"name": "2013 Ford Shelby GT500\u2122",
"thumb": "/static/images/carthumbs/24824.png",
"user_id": "502a754b34fa75280c000a7e"
}
],
"user": {
"id": "502a754b34fa75280c000a7e",
"car_ids": [
"50ace47234fa7557403e7f02",
"508668cc34fa753b78784ca2",
"50c7545334fa750ab8cb3ac2",
"50adf64c34fa750bb036121e"
],
"player_type": "Standard Player",
"username": "WillMckenzie"
}
}
如果我调用App.User.find(“502a754b34fa75280c000a7e”),似乎所有内容都可以正常加载,但是当我尝试访问用户的cars属性时,它会触发第二个http请求到汽车api路由。我的理解是,这不应该是必要的,如果我将id更改为基本的int,则不会。由于我使用Mongo作为我的数据库,我的ID必须采用这种字符串格式。
关于我做错了什么建议?
干杯 将
答案 0 :(得分:0)
以下是答案,以便人们不必深入了解评论:
"我列出的汽车ID不在返回的汽车列表中。他们的抓取方式略有不同,我显然在那里有不好的记录。这意味着它始终认为需要重新加载该记录,以便继续请求。显然当我伪造整数id时,它掩盖了这个。" - OiNutter