Ember data belongs to the Association (JSON format?)

I have two models: "Author" and "Publisher" (Rails), with the publisher hasOne, the author / author belongs to the publisher.

I have the correct settings for Ember models - JS Fiddle - and associations that work when manually clicked in the repository. But on request / publishers, only publisher records are created.

I tried several types of JSON responses:

Author Publishers

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

Publisher with embedded author

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

Thanks for any help!

+1
source share
2 answers

ActiveModelAdapter/ActiveModelSerializer _id/_ids

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

+2

ember- , - -

0

Source: https://habr.com/ru/post/1539379/


All Articles