0
votes

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.

I've commented out any code in the views except for a text line saying Woot. So there shouldn't be any calls for an ancestor object in the views. - BJ McDuck
Are you sure your JSON payload structure matches the structure that Ember Data is expecting? You may need to look at customizing your adapter if you do not have control of the JSON payload coming from the server. - user1225352
I have control over the JSON payload and am just tinkering with that right now. I just tried removing all the side-loaded data and returns functionality to the show page. So it must be something in the serializer, or the hasMany setup. - BJ McDuck
I had someone on IRC that the JSON should be returned with the actual model name. So dream_symbols rather than ancestors. Hasn't worked for me yet. - BJ McDuck
Just found this probably related SO article: stackoverflow.com/questions/13727512/self-join-with-ember-data - BJ McDuck