mercredi 10 juin 2015

Using this.store.filter with the ID of the belongs_to model

I'm trying to retrieve all the layouts for a given account.

/app/models/account.js

import DS from 'ember-data';

export default DS.Model.extend({
  companyName: DS.attr('string'),
  layouts: DS.hasMany('layout')
});

/app/models/layout.js

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  account: DS.belongsTo('account', { async: true })
});

/app/routes/layouts.js

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return Ember.RSVP.hash({
      layouts: this.store.filter('layout', { account_id: 1 }, function(layout) {
        console.log(layout.get('account').content.id);
        return layout.get('account').content.id === 1;
      })
    });
  }
});

The console.log line is outputting the ID that I'm expecting (1). In Ember inspector I can see 5 layout models and under 'Belongs To' I can see: account : <DS.PromiseObject:ember960>. Clicking that brings up content : <batmics@model:account::ember600:1> and clicking that brings up the properties, including the correct ID.

So I've no idea why it's not working :(




Aucun commentaire:

Enregistrer un commentaire