10

I'm inside of a DS.Model-extending class and want to get the current adapter instance. I found some code here:

App.__container__.lookup('adapter:application')

But it looks quite hacky and I'm wondering whether there's a more correct way.

lucas clemente
  • 6,255
  • 8
  • 41
  • 61

2 Answers2

18

This would be a bit better, since you're getting the exact adapter for the model (whether that's ThisModelAdapter, ApplicationAdapter, etc.)

this.store.adapterFor(this.constructor.typeKey)

sheldonbaker
  • 1,089
  • 7
  • 14
5

It appears that the APIs have changed since sheldonnbbaker answered. But in Ember 2.1 the following will do the same thing:

this.store.adapterFor(this.constructor.modelName)
misfo
  • 103
  • 1
  • 4