lundi 23 octobre 2017

Issue with a belongsTo relationships in an ember-engines

I will try to explain the situation.
I have three models, lets call them: room, furnitures, chair.

Now, lets see how the models are declared. room, located in lib/room/app/room.js

export default DS.model.extend({
    name: DS.attr('string'),
    mostPreciousFurniture: DS.belongsTo('furniture')
});

furniture, located in lib/furniture/app/furniture.js

 export default DS.model.extend({
        name: DS.attr('string'),
        type: DS.attr('string') // type of the furniture(chair, table, etc...)
 });

chair, located in lib/chair/app/chair.js

import Furniture from 'web/models/furniture'

export default Furniture.extend({
          material: DS.attr('string')
     });

So we have three model, room with a belongsTo relationships to furniture, chair who is a 'member' of furniture, and furniture who is a basic model.

Now I can set the value of room.mostPreciousFurniture with chair for example(in a form), and when I save my model, my backend server receive the id of the furniture.
But when I try to fetch this relationships in the store, it is not found. This is a problem, because if I want to edit my room model, I cannot access to the previous value of mostPreciousFurniture.

I set the value of mostPreciousFurniture in a components,

setMostPrecious(params)
        {
            let type = params.type; // type here is chair for example
            this.get('store').find(type, params.id).then((furniture) => {
                this.get('room').set('mostPreciousFurniture', furniture);
            });
        }

If I console.log my relationships here, I will say that it is filled, which is a good start. But as I already say, once I refresh my page I can access to the data of room except the mostPreciousFurniture.

I may have missed some information, if you need more please tell me. Any tips is appreciated.




Aucun commentaire:

Enregistrer un commentaire