How to get all parents?


#1

Hey, How to get all parents?

export default DS.Model.extend({
  name: DS.attr('String'),
  parent: DS.belongsTo('category', {inverse: 'children'}),
  children: DS.hasMany('category', {inverse: 'parent'})
});

In templates I would like to display all parents in breadcrumb. this work for one:

{{model.parent.parent.name}}

replace to?

{{#each parents as |category|}}
  {{category.name}}
{{/each}}

in controller:

export default Ember.Controller.extend({
	parents: Ember.computed('model.parent',function(){
		var parent = this.get('model.parent');
		var parentsArray = [];

		function recursive(obj){
		  obj.then(function(){
		  parentsArray.push(obj)
		    if (!Ember.isEmpty(obj.get('parent'))){
		      recursive(obj.get('parent'))
		    }
		})
	      }
	     recursive(parent)

	     return parentsArray
	})
});

this, not work, please help Me :grinning: