Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember: Get current adapter from model

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.

like image 224
lucas clemente Avatar asked Feb 28 '14 23:02

lucas clemente


2 Answers

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)

like image 63
sheldonbaker Avatar answered Nov 09 '22 06:11

sheldonbaker


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)
like image 44
misfo Avatar answered Nov 09 '22 06:11

misfo