Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the repo below to guide you on how to do embedded association. Though they are not using mongodb, the important thing is on the ember-data side, they are doing embedded association.</p> <p><a href="https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js" rel="nofollow">https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js</a></p> <p>Note that here App.PhoneNumber is embedded in App.Contact. But it should give you an idea on how to go abut resolving yours.</p> <pre><code>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') }); </code></pre> <p><a href="https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/store.js" rel="nofollow">https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/store.js</a></p> <pre><code>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() }); </code></pre> <p><a href="https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js" rel="nofollow">https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js</a></p> <pre><code>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(); }, }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload