Ember-data with local storage; Ensure one record exists

I’m looking for some guidance on best practice here. I need to load or create a single model which contains some user preferences. I am using local storage for this particular model.

So far, I haven’t had much luck. Here’s what I have:

# There may or may not be App.UserSettings in local storage
settings = App.UserSettings.find()

settings.addObserver "didLoad", (editors) ->
  console.debug "never reached"
  settings = settings.get("firstObject")

With the asynchronous pattern, how do I account for the case where there are no App.UserSettings in local storage?

I could be thinking about this with old synchronous habits, so if someone could please point out where I’m going wrong, it would be greatly appreciated.

How do I determine that no records of this type exist?

1 Like

Apparently, a similar question was asked on stack overflow:

The poster was able to ask his question with a bit more clarity than I could.

I’m struggling to figure this out as well. Were you ever able to find a solution?

I fiddled with it for a good while, and eventually ended up not using ember-data.

I assume you’re supposed to use the promise or whatever to handle record loading, but in my particular app, where I had rest adapters and localstorage adapters working in concert, it turned out to be easier to just roll my own for the short term.