lundi 26 septembre 2016

Ember-data model resets other relationship when loading hasMany

I have an OrderTask model in my project, that belongs to Order and belongs to assignee which is represented by User model, so the schema looks like this:

// order-task.js
export default Model.extend({
  //...
  order: belongsTo('order', { inverse: 'orderTasks' }),
  assignee: belongsTo('user', { inverse: 'orderTasks' }),
});

// order.js
export default Model.extend({
  // ...
  shop: belongsTo('shop'),
  orderTasks: hasMany('order-task', { inverse: 'order' }),
});

// user.js
export default Model.extend(userValidations, {
  // ...
  shop: belongsTo('shop'),
  orderTasks: hasMany('order-task', { inverse: 'assignee' }),
});

On the order page we fetch tasks via order.get('orderTasks') and server returns all order tasks: completed and active.

In the toolbar we fetch user's tasks via user.get('orderTasks') and server returns only active tasks that assigned to current user.

Every time user.orderTasks is reloaded, the list of order's tasks (order.orderTasks) loses assignee relationship (orderTask.assignee), but only for completed tasks.

Probably this happens due to the fact that server returns only active user tasks, BUT I can't understand how this affects order tasks. Is it possible to define relationships so they don't interfere in the data store like that?

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire