dimanche 2 août 2015

How to get the last object from a query?

I have the following:

// In the service
me: Ember.computed('token', function() {
  return this.container.lookup('service:store').findRecord('user', 63);
}

// In the template - Works
{{this.currentSession.me.profile.firstName}}

Above works as expected. However, if I replace findRecord with query and throw it a filter param:

// In the service
me: Ember.computed('token', function() {
  return this.container.lookup('service:store').query('user', { filter: { token: this.get('token') } });
}

// In the template - Works
{{this.currentSession.me.lastObject.profile.firstName}}

The lastObject is required, since the result from query is a collection. I am wondering if it is possible to get this work without doing lastObject. i.e.

{{this.currentSession.me.profile.firstName}}

I tried to put the lastObject in the computed property, like:

return this.container.lookup('service:store').query('user', { filter: { token: this.get('token') } }).lastObject;

To no avail. Any thoughts?




Aucun commentaire:

Enregistrer un commentaire