Skip to content

Instantly share code, notes, and snippets.

@jcloutz
Created December 3, 2015 14:27
Show Gist options
  • Save jcloutz/f07e6cbe4eee273d36e4 to your computer and use it in GitHub Desktop.
Save jcloutz/f07e6cbe4eee273d36e4 to your computer and use it in GitHub Desktop.
Ember JS Relationships Not updating
import DS from 'ember-data';
export default DS.Model.extend({
item_no: DS.attr('string'),
name: DS.attr('string'),
notes: DS.attr('string'),
barcode: DS.attr('string'),
vendor_item_no: DS.attr('string'),
vendor_dept: DS.attr('string'),
orders: DS.hasMany('order', {async: true}),
search_name: Ember.computed('item_no', 'name', function() {
return this.get('item_no') + ' - ' + this.get('name');
})
});
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
requested_qty: DS.attr('number'),
notes: DS.attr('string'),
due_date: DS.attr('date'),
job: DS.belongsTo('job', {async: true}),
item: DS.belongsTo('item', {async: true}),
status: DS.attr('string', {defaultValue: 'Open'}),
createdAt: DS.attr('date', {
defaultValue() { return new Date(); }
}),
order_no: Ember.computed('id', {
get() {
let order_no = parseInt(this.get('id')) + 10000;
return order_no;
}
})
});
<h1>Work Orders</h1>
<table class="table table-hover table-responsive">
<thead>
<tr>
<th>Order No.</th>
<th>Job No.</th>
<th>Item No.</th>
<th>Quantity</th>
<th>Status</th>
<th>Due Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{{#each model as |order|}}
<tr>
<td>{{link-to order.order_no 'orders.show' order}}</td>
<td>{{link-to order.job.ref_no 'jobs.show' order.job}} - {{order.job.creator.name}}</td>
<td>{{order.item.item_no}}</td>
<td>{{order.requested_qty}}</td>
<td>{{order.status}}</td>
<td>{{order.due_date}}</td>
<td>{{link-to 'Edit' 'orders.edit' order}}</td>
</tr>
{{/each}}
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment