How to include associations when saving with ActiveModelAdapter


#1

I’ve found lots of bits and pieces to do with how to serialize associations when saving with the ActiveModelAdapter but nothing seems to work.

The most promising looking approach was to simply specify embedded:‘always’ as an option on the association e.g.

var attr = DS.attr;
var belongsTo = DS.belongsTo;

Zapnito.Archive = DS.Model.extend({
	video: belongsTo('video', {embedded:'always'}),
	durationSeconds: attr('number'),
	url: attr('string')
});

and

var attr = DS.attr;
var belongsTo = DS.belongsTo;

Zapnito.Video = DS.Model.extend({
	title: attr('string'),
	introduction: attr('string'),
	archive: belongsTo('archive', {embedded:'always'})
});

but when I try save an archive for instance there’s just a video_id rather than the expected video_attributes property. Is what I’m trying to do possible with the ActiveModelAdapter?


#2

I’ve opened a pull request to add a guide for this,


#3

have you tried this? http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html

I think you need to use that mixin.