Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Fetch nested relationship data fails

$
0
0

@devtoro wrote:

I cannot fetch nested relationship from the store of my ember application. The relationship is as follows:

project <=> client <=> offices.

Versions:

Ember: 2.12.0
Ember Data: v2.12.1

Here are my models:

project:
import DS from 'ember-data';

export default DS.Model.extend({
  title: DS.attr('string'),
  client: DS.belongsTo('client')
});

client:

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string') ,
  projects: DS.hasMany('project'),
  offices: DS.hasMany('office')
});

office:

import DS from 'ember-data';
export default DS.Model.extend({
  country: DS.attr('string'),
  client: DS.belongsTo('client')
});

Here is my route:

import Ember from 'ember';

export default Ember.Route.extend({
  model(params) {
    return this.get('store').findRecord('project', 1);
  }

The requested "offices" are in the payload from the server and are stored in the store.
In my route, my model is a project object. The client of the project has 2 offices. When I try to fetch the client, everything works like a charm. When I additionally try to fetch the client's offices I get 0 records. This is how I try to fetch them:

let client = model.get('client');
client.get('offices');

When the promise is resolved, there are no records.

Any ideas?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles