Note that there are some explanatory texts on larger screens.

plurals
  1. POpersisting parent and embedded record in ember-data
    primarykey
    data
    text
    <p>I have the following models:</p> <pre><code>App.Company = DS.Model.extend({ name: DS.attr('string'), accounts: DS.hasMany('App.Account', { inverse: 'company' }) }); App.Account = DS.Model.extend({ login: DS.attr('string'), first_name: DS.attr('string'), last_name: DS.attr('string'), email: DS.attr('string'), password: DS.attr('string'), password_confirmation: DS.attr('string'), company: DS.belongsTo('App.Company') }); </code></pre> <p>The company is defined as being embedded in the account:</p> <pre><code>DS.RESTAdapter.map('App.Account', { company: { embedded: 'always' } }); </code></pre> <p>When I create a new account, the company data is correctly embedded in the account data and I'm seeing the POST request that I expect on the server side:</p> <pre><code>Started POST "/accounts" for 127.0.0.1 at 2013-06-27 13:30:53 +0200 Processing by AdminUsersController#create as JSON Parameters: {"account"=&gt;{"login"=&gt;"fsdfdf", "first_name"=&gt;"fgdfgh", "last_name"=&gt;"fsfdsfdsfsd@fgfdgdfgf.de", "email"=&gt;"dsfdsgds@frgdfgfgdfg.de", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]", "company"=&gt;{"name"=&gt;"gfdhgtrhzrh"}}} </code></pre> <p>However, I'm also seeing an additional POST request for the company itself:</p> <pre><code>Started POST "/companies" for 127.0.0.1 at 2013-06-27 13:30:53 +0200 Processing by CompaniesController#create as JSON Parameters: {"company"=&gt;{"name"=&gt;"gfdhgtrhzrh"}} </code></pre> <p>I'm setting up the models as follows:</p> <pre><code>this.transaction = this.get('store').transaction(); var account = this.transaction.createRecord(App.Account, {}); account.set('company', this.transaction.createRecord(App.Company, {})); </code></pre> <p>When the user clicks save, I simply commit the transaction:</p> <pre><code>this.transaction.commit(); </code></pre> <p>Is that a bug or am I doing something wrong? Spent quite some time on that already...</p> <p>Thanks for help!</p>
    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.
 

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