Reflexive relationships


Has anyone gotten Ember to work with Reflexive relationships? I’m using ember-data-1.0.0.beta.7 with ActiveModelAdapter and Rails. My model looks like:

App.Foobar = DS.model.extend({
  name: DS.attr('string'),
  ancestor: DS.belongsTo('foobar'),
  descendants: DS.hasMany('foobar')

and the returned JSON looks like:

  "foobar": {"id": 2, "name": "lorem"},
  "descendants": [
    {"id": 3, "name": "John"},
    {"id": 4, "name": "Smith"}
  "ancestor": {"id": 6, "name": "ipsum"}

I believe the JSON format is what is described in the documentation, but I wouldn’t be surprised if there’s something amiss. I also tried turning async to false and I still got the same error.

This is the error I got:

"Error while loading route: Ember.Error@http://localhost:3000/assets/ember.js?body=1:837
RESTAdapter<.ajax/< /hash.success@http://localhost:3000/assets/ember-data.js?body=1:1524

And in the Ember Inspector it tells me a promise was rejected because the model wasn’t found.

Any help would be greatly appreciated.


I am able to get it working with the FixtureAdapter, but still no luck using the ActiveModelAdapter. A couple of corrections to the code above.

  1. In the Foobar model, ancestor needs to have many foobar as well
    ancestor: DS.hasMany(‘foobar’)
  2. The returned JSON needs to embed the descendants and ancestor IDs within “foobar”:
  "foobar": {"id": 2, "name": "lorem", "descendants": [3,4], "ancestors": [6]},
  "descendants": [
    {"id": 3, "name": "John"},
    {"id": 4, "name": "Smith"}
  "ancestor": {"id": 6, "name": "ipsum"}

Again, any help with this is greatly appreciated. Mike


Hey I’m trying to solve something similar. I’m using the ancestry gem for parent/children relationships, is that what you mean by reflexive?

The error I get is only on the show pages for an entry with a parent. I get Error: No model was found for 'ancestor'.

More details here:


Just found these entries on SO and here:


Is there any example for Ember reflexive relation ?


Ya, check out this repo I made about this exact thing.

It’s not CLI, but it was how I got it working in my app.