0

i'm working with ember data rev-11 and django tastypie. Looks like now ember-data does not support embeded resources but support sideloads (django tastypie does not support it). What is the best solution?

Thanks

Andrew Fan
  • 87
  • 2
  • 8
  • Make sure to check this Ember-Data [Adapter for Django Tastypie](https://github.com/escalant3/ember-data-tastypie-adapter) – MilkyWayJoe Jan 25 '13 at 16:44
  • I'm marking this as a dupe since the answer below is no longer relevant for Ember Data 1.0 beta – Kingpin2k Aug 01 '14 at 04:26

1 Answers1

16

This is not valid for Ember Data 1.0 beta+, see duplicate answer

Ember-data still supports embedded. You just need the right configuration. Here how you can do it:

DS.RESTAdapter.map('App.Foo',{
    bar:{
        embedded:'always'
    }
})

App.Foo = DS.Model.extend({
    bar: DS.belongsTo(App.Bar,{embedded:'always'}),
});

Available values for embedded are: always and load.

load: The child records are embedded when loading, but should be saved as standalone records. In order for this to work, the child records must have an ID.

always: The child records are embedded when loading, and are saved embedded in the same record. This, of course, affects the dirtiness of the records (if the child record changes, the adapter will mark the parent record as dirty).

Similar settings apply for HasMany relationship, see this reply for more details

Community
  • 1
  • 1
ken
  • 3,745
  • 6
  • 34
  • 49
  • Need help on the issue of embedded always inside embedded always. Posted a question here http://stackoverflow.com/questions/14896049/ember-data-multi-level-hierarchy-with-embedded-always Loader does not load inner JSON as an object. – sudhanshu Feb 18 '13 at 12:05
  • I followed these instructions. I have a `location` embedded model, which has `latitude` and `longitude` attributes. Whenever one of the attribute changes, the parent record is not marked as dirty, but the `location` model is. Using Ember-Data rev 12. Isn't the parent record supposed to be also marked as dirty? – miguelcobain Apr 29 '13 at 16:19
  • Well, I've changed from FixtureAdapter to RESTAdapter. It seems to work properly now. – miguelcobain May 30 '13 at 15:23
  • Does this work when you send the parent object back (in a PUT request) back to the server? Will the child object be embedded in the parent? Or this only work when you load the parent record when your server returns the record to you? I tried and I didn't see the child been embedded. Any pointer is greatly appreciated! – lionel Sep 15 '13 at 06:11