0

我正在使用 Ember 1.5、Ember-Data 1.0.0-beta.7 和祖先 gem。

我有一个带有parentand的模型ancestors,但是任何具有 aparentancestor得到这个奇怪错误并失败的模型条目。

错误:
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"
    ]
  }
}

我需要用belongsTohasMany设置来改变一些东西。有点难倒这里。

4

0 回答 0