Controlling Model's typeKey


#1

I’m having trouble figuring the correct way to use Ember-Data to allow me use a model named “preferences” (plural). What I try is overriding application serializer:

typeForRoot: (root) ->
    return 'preferences' if root is 'preferences'
    @_super root

But when trying to .save() a model I get: Uncaught Error: No model was found for 'preference’ Looking closer I see the model’s constructor has a property ‘typeKey’ which is set to ‘preference’ (singular)

How can I disable this behavior for just this model?


#2

To make it a little clearer maybe, I have in my route:

  model: (params) ->
    @store.find('preferences', params.preferences_id).then (p) ->
      console.log p.constructor.typeKey
      p

And in the console I see ‘preference’ (single). I don’t understand why…


#3

update:

The only way I found to overcome my problem is overriding my store’s modelFor method:

Store = DS.Store.extend
  modelFor: (name) ->
    name = 'preferences' if name is 'preference'
    @_super name

I’m really not happy with this solution… though