【发布时间】:2013-11-18 17:16:30
【问题描述】:
我正在使用 Ember v1.0.0 和 Ember-Data v1.0.0-beta.3 构建一个简单的 Ember 应用程序。我有一个名为“Categoria”的模型
categoria.coffee:
App.Categoria = DS.Model.extend
nombre: DS.attr 'string'
simplified: DS.attr 'boolean'
candidatos: DS.hasMany 'candidato'
当我尝试通过它的 id 查找“类别”时,我总是收到错误消息: 断言失败:找不到“类别”的模型
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
)
由于是西班牙语命名的模型,我已经指定了变形规则。
store.coffee:
Ember.Inflector.inflector.irregular('categoria', 'categorias')
Ember.Inflector.inflector.rules.irregularInverse['categorias'] = 'categoria'
App.ApplicationAdapter = DS.ActiveModelAdapter()
App.ApplicationSerializer = DS.ActiveModelSerializer.extend()
我想知道 Store 的 find 方法是否使用了一组不同的变形规则? 或者还有其他地方我应该为这个模型声明变形规则吗?
值得一提的是,针对此模型向服务器发出的请求是正确的(发送到正确的 URL),并且它们的响应格式正确。
我尝试对store.find 方法使用不同的语法,如Ember Guides#Method Find (http://emberjs.com/api/data/classes/DS.Store.html#method_find) 中所述,但错误是相同的。
【问题讨论】:
-
这很有趣,它使用了 ember 变形器规则。让我看看我们能不能帮你找到它。
-
@kingpin2k:谢谢!我为这个问题浪费了一天的时间,我从没想过“Ember.Inflector.inflector.singular”,但效果很好!
标签: ember.js ember-data