Ember-data embedded objects stored as separate objects

前端 未结 1 839
面向向阳花
面向向阳花 2020-12-22 00:32

I was wondering if it would be possible to define a model stored into another one.

I have this kind of structure:

Model Contact
    String name
    M         


        
相关标签:
1条回答
  • 2020-12-22 01:25

    You are using the RESTadapter... when you are saving you want to serialize all the relationships embedded?

    When you are saving or updating your record pass in the options hash to the toJSON method with

    {associations: true}
    

    Take a look at the unit tests on ember-data for examples: https://github.com/emberjs/data/blob/master/packages/ember-data/tests/unit/to_json_test.js

    deepEqual(record.toJSON({ associations: true }),
            { id: 1, name: "Chad", phone_numbers: [{
                id: 7,
                number: '123'
              },
              {
                id: 8,
                number: '345'
              },
              {
                id: 9,
                number: '789'
              }
            ]},
            "association is updated after editing associations array");
    });
    

    Hope this helps..

    0 讨论(0)
提交回复
热议问题