Question

I have two models 'Author' and 'Publisher' (Rails), with a publisher hasOne author / author belongsTo publisher relationship.

I have the Ember models setup correctly -- JS Fiddle -- and the associations working when I manually push into the store. But only the publisher records are created when requesting /publishers index.

I've tried several types of JSON responses:

Publishers with author

{
    "publishers": [
        {
            "id": 1,
            "name": "Test P 1",
            "author": 1
        }
    ],
    "author": {
        "id": 1,
        "name": "Test A 1",
        "publisher": 1
    }
}

Publishers with authors

{
    "publishers": [
        {
            "id": 1,
            "name": "Test P 1",
            "author": 1
        }
    ],
    "authors": [{
        "id": 1,
        "name": "Test A 1",
        "publisher": 1
    }]
}

Publishers with author embedded

{
    "publishers": [
        {
            "id": 1,
            "name": "Test P 1",
            "author": {
              "id": 1
              "name": "Test A 1"
            }
        }
    ]
}

Thanks for any help!

Was it helpful?

Solution

The ActiveModelAdapter/ActiveModelSerializer expects _id/_ids to be appended on relationships

{
    "publishers": [
        {
            "id": 1,
            "name": "Test P 1",
            "author_id": 1
        }
    ],
    "authors": [{
        "id": 1,
        "name": "Test A 1",
        "publisher_id": 1
    }]
}

http://jsfiddle.net/6Z2AL/1/

OTHER TIPS

Adding a link to ember-data issue in case it helps anyone -- single object push payload

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top