2
votes

I'm using ember rc3 and ember-data 12 (sha e324f0e) (basically the files recommended in the guides). I have 2 models set up as follows:

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')
})

The json returned is

{
    "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"
    }
}

Everything seems to load fine if I call App.User.find("502a754b34fa75280c000a7e"), but when I try and access the cars property on the user it triggers a second http request to the cars api route. It was my understanding that this shouldn't be necessary, and if I change the ids to basic ints, it doesn't. As I'm using Mongo as my DB my ids have to be in this string format.

Any suggestions as to what I'm doing wrong?

Cheers Will

1
Could I suggest you to update both ember and ember-data ?sly7_7
I have tried using the latest versions of ember and ember-data, but hit other issues. I think I need to update my code to work with the latest version of the API but they haven't listed the breaking changes yet. Do you know specific versions that work? Will give it another try tomorrow.OiNutter
I'd try the ember rc5 and ember-data 13 (where you don't need to define the store's VERSION anymore.sly7_7
Ok, I've tried both the versions you suggested and the latest versions of both ember and ember-data but I'm still having the same issue. Works fine with integer ids, but as soon as I switch it to use Mongo style string ids, it doesn't want to know.OiNutter
Did a bit more digging and tried to track the flow through ember data, and it turns out I had one car id listed that wasn't in the list of cars returned. They're grabbed slightly differently and I obviously had a bad record in there. This meant it always thought it needed to reload that record so would keep requesting. Obviously when I was faking the integer ids it was masking this. Apologies, thanks for everyone's help!OiNutter

1 Answers

0
votes

Here's the answer so people don't have to dig through the comments:

"I had one car id listed that wasn't in the list of cars returned. They're grabbed slightly differently and I obviously had a bad record in there. This meant it always thought it needed to reload that record so would keep requesting. Obviously when I was faking the integer ids it was masking this." - OiNutter