Is there any example of a reflexive attitude?
I am trying to echo the json answer most likely mentioned below and I want to achieve this model using a reflexive relationship.
{
folders : [
{
id : 1,
folders [ { id : 1, folders : [] } ]
},
{
id : 2,
folders : [{ id : 1, folders : [ {id:1 , folders : [] }] }]
}
]
}
I have here my try children: DS.hasMany ('folders', {inverse: 'parent'}), parent: DS.belongsTo ('folders', {inverse: 'children'})
But it doesn't work at all. is there any example?
+3
source to share
1 answer
I have a similar structure for nested categories, modeled this way
In my models /category.js
export default DS.Model.extend({
name: DS.attr('string'),
description: DS.attr('string'),
master: DS.belongsTo('category', {inverse: null})
});
Then in my routes /products.js I define the model hook like this
model: function() {
return {
products: this.store.findAll('product'),
categories: this.store.findAll('category')
};
}
From controllers /products.js I have access to categories and their main categories like this
var categories = this.get('model').categories;
for (var i=0; i < categories.get('length'); i++) {
var master = categories.objectAt(i).get('master').get('id');
It seems that ember takes care of everything in the background after all.
0
source to share