0

After I learned that the BasicAdapter in Ember Data has been removed, I decided to switch from Ember Data to Ember Model because the API I work with is not totally RESTful (and I need more flexibility in general).

I'm wondering how to "translate" some parts of my code that used to work with the FixtureAdapter from Ember Data.

Here for example, I get a list of profiles but I want to directly redirect to the first one. That means, accessing /profiles will redirect me to something like /profiles/123. How can I do that with Ember Model? (using the FixtureAdapter, as a starting point).

App.ProfilesIndexRoute = Ember.Route.extend {

  redirect: ->
    App.Profile.find().then (profiles) =>
      @transitionTo 'profile', profiles.objectAt(0)

}

When I do that with Ember Model, I have the following error showing up in my console:

Uncaught TypeError: Object [object Object] has no method 'then' 

Thanks for your help!

Vinch
  • 1,551
  • 3
  • 13
  • 15

1 Answers1

3

Try using:

App.Profile.fetch().then(profiles)

The fetch() function will give you a promise that you can call then() on

ianpetzer
  • 1,828
  • 1
  • 16
  • 21
  • Cool! It works. But now, how can I get the first item of the Array? objectAt doesn't work here :-( – Vinch Aug 21 '13 at 18:03
  • The promise wraps and Ember.RecordArray defined in Ember-model which extends from the core Ember ArrayProxy. You should be able to call objectAt on the profiles object once the promise has resolved. ie: inside the 'then' function. ps: Ember has a convenience method profiles.get('firstObject').. which is the same as profiles.objectAt(0) – ianpetzer Aug 22 '13 at 04:45