kurko / ember-json-api

JSON API adapter for Ember Data.
MIT License
254 stars 62 forks source link

Related/linked entities don't load properly #62

Closed lohengrin332 closed 9 years ago

lohengrin332 commented 9 years ago

With two models related in a 1:1 fashion:

Person:

lead: DS.belongsTo('lead', { async: true }),
firstName: DS.attr('string'),
lastName: DS.attr('string'),
photo_url: DS.attr('string'),

Lead:

person: DS.belongsTo('person', { async: true }),
username: DS.attr('string'),

I'm receiving the following JSON from my web service:

{
    "leads": [
        {
            "id": 13,
            "person_id": 56,
            "username": "joe@gmail.com"
            "type": "leads"
            "href": "/leads/13",
            "links": {
                "person": 56
            },
        },
        {
            "id": 14,
            "person_id": 57,
            "username": "joe2@gmail.com"
            "type": "leads"
            "href": "/leads/14",
            "links": {
                "person": 57
            },
        },
    ],
    "linked": {
        "person": [
            {
                "id": 56,
                "first_name": "Emily",
                "last_name": "Dougals",
                "gender": "Female",
                "type": "peoples",
                "href": "/people/56",
            },
            {
                "id": 57,
                "first_name": "Joe",
                "last_name": "Ingersoll",
                "gender": "Male",
                "type": "peoples",
                "href": "/people/57",
            },
        ]
    },
    "links": {
        "leads.person": {
            "href": "/people/{person.person_id}",
            "type": "peoples"
        }
    }
}

All four objects are being loaded as expected into their respective models, as seen in the Ember Inspector. However, the warning WARNING: The payload for 'people@model:lead:' contains these unknown keys: [href,person_id,peoples] is received, and the objects are not acting like they are linked. In other words, I'm able to access 'lead.username' in my templates, but not 'lead.person.firstName' or any other field on the person object.

When I convert my web service response and use the standard ActiveModel Adapter/Serializer in Ember it functions as expected.

I'm happy to provide more information as needed. Thank you.

jonkoops commented 9 years ago

I am closing this issue due to the impending deprecation in favour of the official Ember Data adapter. If you think this is an issue that relates to Ember Data please report the issue there.