jeudi 21 avril 2016

Link hasMany/belongsTo associated objects loaded through separate requests?

I'm using Ember/Ember Data 2.4

I have a simple hasMany belongsTo relationship defined as follows:

// models/employee.js
export default DS.Model.extend({
  shifts: DS.hasMany('shift', { async: false })
})

// models/shift.js
export default DS.Model.extend({
  employee: DS.belongsTo('employee', { async: false })
})

I load all employees through an initial request on the homepage of the application. Then, when the use navigates to the calendar page, I fetch shifts for the given week in another requests. The shift JSON includes an employee_id.

After shifts have been loaded, shift.get('employee') returns null.

How can I associate the newly loaded shift records with employee records that already exist in the store?




Aucun commentaire:

Enregistrer un commentaire