firstObject in Router model() function?

In this case:

model: function (params) {
    return Ember.RSVP.hash({
      room: this.store.find('room', {url:params.room_url}),
      user: this.store.find('user', 1)
    });
  },

How do I set the “room” model to a firstObject? (I have solved this in a beforeModel function, but that seems unnecessary.)

setupController: function(controller, model) {
   model.set('room', model.get('room.firstObject'));

   this._super.apply(this, arguments);
}

Another alternative:

model: function(params) {
  return Ember.RSVP.hash({
    room: this.store.find('room', {url:params.room_url}).then(function(result){ 
      return result.get('firstObject');
    }),
    user: this.store.find('user', 1)
  });
},
2 Likes