我使用Ember 1.5,Ember-Data 1.0.0-beta.7和祖先宝石。
我的模型包含parent
和ancestors
,但是parent
或ancestor
的任何模型条目都会出现这种奇怪的错误并失败。
Ember Inspector ($E): Error: No model was found for 'ancestor'
at new Error (native)
at Error.Ember.Error (http://localhost:8080/assets/ember.js?body=1:911:19)
at Ember.Object.extend.modelFor (http://localhost:8080/assets/ember-data.js?body=1:9808:33)
at JSONSerializer.extend.extractSingle (http://localhost:8080/assets/ember-data.js?body=1:3021:28)
at superWrapper [as extractSingle] (http://localhost:8080/assets/ember.js?body=1:1293:16)
at Ember.Object.extend.extractFind (http://localhost:8080/assets/ember-data.js?body=1:2483:21)
at Ember.Object.extend.extract (http://localhost:8080/assets/ember-data.js?body=1:2368:37)
at http://localhost:8080/assets/ember-data.js?body=1:10340:34
at invokeCallback (http://localhost:8080/assets/ember.js?body=1:10014:19)
at publish (http://localhost:8080/assets/ember.js?body=1:9684:9) VM6302:164
我已经注释掉了一堆代码,寻找我要求ancestor
的任何地方,但我无法找到它。
以下是我目前正在使用的代码,但仍然存在此错误。
#models/dream_symbol.js.coffee
attr = DS.attr
App.DreamSymbol = DS.Model.extend
description: attr 'string'
image: attr 'string'
name: attr 'string'
parent_id: attr 'number'
path: attr 'string'
rails_id: attr 'number'
thumbnail: attr 'string'
user: DS.belongsTo 'user'
parent: DS.belongsTo('dream_symbol',
inverse: 'children'
embedded: 'always'
)
# ancestors: DS.hasMany('dream_symbol',
# inverse: 'children'
# embedded: 'always'
# )
children: DS.hasMany('dream_symbol',
inverse: 'parent'
embedded: 'always'
)
siblings: DS.hasMany('dream_symbol',
inverse: 'siblings'
embedded: 'always'
)
interpretations: DS.hasMany('interpretation',
embedded: 'always'
)
serialize: ->
@getProperties [ 'guid', 'image', 'name', 'description', 'parent', 'children', 'siblings', 'parent_id', 'interpretations', 'path', 'rails_id' ]
我在上面的代码中注释掉并删除了对ancestor
的任何引用。
以下是我的路线,我已经完整地评论了我的DreamSymbolShowController
。
# Show Route
App.DreamSymbolsShowRoute = Ember.Route.extend
model: (params)->
@store.find 'dream_symbol', params.id
actions:
edit: ->
@transitionTo 'dream_symbols.edit', @currentModel
new: (params)->
referrer = @currentModel.get 'id'
parent_id = ( if params then params.id else null )
@transitionTo('dream_symbols.new').then (newRoute)->
newRoute.controller.set 'previous', referrer
newRoute.currentModel.set 'parent_id', parent_id
是否有人想过要试着去研究为什么我会在子页面上出现错误而不是父页面,以及我能做些什么呢?
这是我目前获得的JSON回复:
{
ancestors: [
{
id: "body-parts",
name: "Body Parts",
description: "Qoop",
user_id: null,
image: null,
thumbnail: null,
rails_id: 24
}
],
children: [ ],
parent: [
{
id: "body-parts",
name: "Body Parts",
description: "Qoop",
user_id: null,
image: null,
thumbnail: null,
rails_id: 24
}
],
siblings: [
{
id: "root-level-child",
name: "Hand",
description: "ff",
user_id: null,
image: null,
thumbnail: null,
rails_id: 25
}
],
dream_symbol: {
id: "root-level-child",
description: "ff",
image: null,
name: "Hand",
parent_rails_id: 24,
rails_id: 25,
thumbnail: null,
user_id: null,
ancestors: [
"body-parts"
],
children: [ ],
parent: "body-parts",
siblings: [
"root-level-child"
]
}
}
我需要使用belongsTo
和hasMany
设置更改某些内容。有点难过这里。