Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does store.find() method use different inflection rules from ember-inflector?

I'm building a simple Ember application using Ember v1.0.0 and Ember-Data v1.0.0-beta.3. I have a model called 'Categoria'

categoria.coffee:

App.Categoria = DS.Model.extend
  nombre: DS.attr 'string'
  simplified: DS.attr 'boolean'
  candidatos: DS.hasMany 'candidato'

When I try to find a 'Categoria' by it's id, I always get error message: Assertion failed: No model was found for 'categorium'

categoria_route.coffee:

App.CategoriaRoute = Em.Route.extend(
  model: (params)->
    @store.find('categoria', params.categoria_id)
)

App.CategoriaIndexRoute = Em.Route.extend(
  model: ->
    categoria = @modelFor('categoria')
    categoria.reload() if categoria.get('simplified') 
    categoria
)

I've specified the inflections rules, due the spanish-named model.

store.coffee:

Ember.Inflector.inflector.irregular('categoria', 'categorias')
Ember.Inflector.inflector.rules.irregularInverse['categorias'] = 'categoria'
App.ApplicationAdapter = DS.ActiveModelAdapter()
App.ApplicationSerializer = DS.ActiveModelSerializer.extend()

I'm wondering if the find method of the Store uses a different set of inflections rules? or is there any other place where I should declare the inflection rules for this model?

It worths to mention that requests to the server for this model are made correctly (to the right URL) and they're responded well formed.

I've tried to use different syntax for the store.find method as mentioned in the Ember Guides#Method Find (http://emberjs.com/api/data/classes/DS.Store.html#method_find) but the error is the same.

like image 702
user2716877 Avatar asked Nov 18 '13 17:11

user2716877


1 Answers

The problem is when it tries to singularize the json response, it attempts to singularize categoria and it returns categorium, your pluralization was working fine.

var iff = Ember.Inflector.inflector;

iff.irregular('categoria', 'categorias');
// this adds a test for when it finds categoria and you are trying to singularize, return categoria
iff.singular(/categoria/, 'categoria');

http://emberjs.jsbin.com/ICeGuzuX/3/edit

like image 140
Kingpin2k Avatar answered Nov 15 '22 08:11

Kingpin2k