Error in parent/child relationships in Ember

家住魔仙堡 提交于 2019-11-28 12:45:49

问题


I'm using Ember 1.5, Ember-Data 1.0.0-beta.7 and the ancestry gem.

I have a model with a parent and ancestors, but any model entries that have a parent or ancestor get this weird error and fail.

Error:
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

I've commented out a bunch of code looking for anywhere I'm calling for an ancestor but I can't find it.

Below is the code I've currently got in place that is still throwing this error.

#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' ]

I commented out and removed any references to ancestor in the above code. Below is my routes, and I've completely commented out my 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

DOes anyone have a thought on what to try to look into why I'd be getting errors on child pages but not parent pages, and what I can do about it?

UPDATE:

Here's my current JSON response I'm getting:

{
  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"
    ]
  }
}

There's something I need to change with the belongsTo and hasMany setups. Kind of stumped over here.

来源:https://stackoverflow.com/questions/24474369/error-in-parent-child-relationships-in-ember

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!