Note that there are some explanatory texts on larger screens.

plurals
  1. POcreateRecord with belongsTo association
    primarykey
    data
    text
    <p>I'm trying to store a record with a belongsTo association, but the associated ID is always empty:</p> <p><strong>Customer Model</strong></p> <pre><code>Docket.Customer = DS.Model.extend({ name: DS.attr('string'), initial: DS.attr('string'), description: DS.attr('string'), number: DS.attr('string'), archived: DS.attr('boolean'), projects: DS.hasMany('project',{ async: true }) }); </code></pre> <p><strong>Project Model</strong></p> <pre><code>Docket.Project = DS.Model.extend({ name: DS.attr('string'), description: DS.attr('string'), number: DS.attr('string'), archived: DS.attr('boolean'), customer: DS.belongsTo('customer') }); </code></pre> <p><strong>Save action in ProjectsController</strong></p> <pre><code>var _this = this; // create new record var project = this.store.createRecord('project', this.getProperties('name','number', 'description', 'archived')); // add customer with id 22 to project this.store.find('customer', 22).then(function(customer) { project.set('customer', customer); }); // save if validation passes, otherwise show errors project.save().then(function(){ _this.resetAndCloseForm(form); }, function(response){ _this.set('errors',response.errors); }); </code></pre> <p>The json sended to server is always this:</p> <pre><code>archived: false customer_id: null description: null name: "foobar" number: null </code></pre> <p>I want to choose the customer of the project in a selectbox. Are there any smart ways to get the selected customer as record or do I have to load it over the ID?</p> <pre><code>{{view Ember.Select viewName="select" contentBinding="customers" optionLabelPath="content.name" optionValuePath="content.id" prompt="Pick a customer:" selectionBinding="selectedCustomer" }} </code></pre>
    singulars
    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.
 

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