以下のレポを使用して、埋め込み関連付けを行う方法をガイドできます。彼らはmongodbを使用していませんが、重要なことはember-data側にあり、組み込みの関連付けを行っています。
https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js
ここで App.PhoneNumber は App.Contact に埋め込まれていることに注意してください。しかし、それはあなたの問題を解決する方法についてのアイデアを与えるはずです。
App.Contact = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
email: DS.attr('string'),
notes: DS.attr('string'),
phoneNumbers: DS.hasMany('App.PhoneNumber'),
});
App.PhoneNumber = DS.Model.extend({
number: DS.attr('string'),
contact: DS.belongsTo('App.Contact')
});
https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/store.js
App.Adapter = DS.RESTAdapter.extend({
bulkCommit: false
});
App.Adapter.map('App.Contact', {
phoneNumbers: {embedded: 'always'}
});
App.Store = DS.Store.extend({
revision: 12,
adapter: App.Adapter.create()
});
https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js
App.ContactEditController = Em.ObjectController.extend({
needs: ['contact'],
startEditing: function() {
// add the contact and its associated phone numbers to a local transaction
var contact = this.get('content');
var transaction = contact.get('store').transaction();
transaction.add(contact);
contact.get('phoneNumbers').forEach(function(phoneNumber) {
transaction.add(phoneNumber);
});
this.transaction = transaction;
},
save: function() {
this.transaction.commit();
},
addPhoneNumber: function() {
this.get('content.phoneNumbers').createRecord();
},
});