Embedded belongsTo to an unsaved record creates two POST request


#1

I got an issue when i try to add an embedded belongTo to an unsaved record. When committing the transaction, I got two POST request. I don’t know if I’m doing something wrong or not…

Here’s my models and mapping:

Comment = App.Comment = DS.Model.extend({
  title: DS.attr('string')
});

Group = App.Address = DS.Model.extend({
  name: DS.attr('string')
});

Post = App.Post = DS.Model.extend({
  title: DS.attr('string'),
  comments: DS.hasMany(Comment),
  group: DS.belongsTo(Group)
});

DS.RESTAdapte.map(Post, {
  comments: { embedded: 'always' },
  group: { embedded: 'always' }
});

My transaction

var transaction = store.transaction();
var post = transaction.createRecord(Post, {
  title: 'This post is unsaved'
});

post.get('comments').createRecord({ title: 'This embedded record is also unsaved' });
post.set('group', Group.createRecord({ name: 'My Group' }));

transaction.commit();

Then I will have two POST request, one on ’/post’ wich is good and another one on ***’/group’***.

Am I doing something wrong ? Thanks you !


#2

Sorry about this post, I’ll have to ask my question on stackoverflow.

If a moderator can delete my topic, thanks !