Quantcast
Viewing all articles
Browse latest Browse all 4826

Resolve related models promises to show it on handlebars templates

@kamillacrozara wrote:

Hey there! I have relationships like these on my models:

    //app/models/veiculo.js
    export default DS.Model.extend({
      atendimento: DS.belongsTo('atendimento-veiculo'),
      atividade: DS.belongsTo('atividade-veiculo'),
    });


    //app/models/atendimento-veiculo.js
    import DS from 'ember-data';

    export default DS.Model.extend({
      atendimento: DS.attr('string')
    });


    //app/models/atividade-veiculo.js
    import DS from 'ember-data';

    export default DS.Model.extend({
      atividade: DS.attr('string')
    });

And I have a payload like this:

"data": [
{
    "attributes": {
        "placa": "JJJ1111",
        "placa-vinculada": "JJJ5555",
        "atendimento": {
            "data": {
                "attributes": {
                    "atendimento": "Atendimento Teste"
                },
                "id": "1",
                "links": {
                    "self": "/api/v1.0/atendimentos-veiculo/1"
                },
                "type": "atendimento_veiculo"
            },
            "links": {
            "self": "/api/v1.0/atendimentos-veiculo/1"
            }
        },
        "atividade": {
            "data": {
                "attributes": {
                    "atividade": "Atividade Teste"
                },
                "id": "1",
                "links": {
                    "self": "/api/v1.0/atividades-veiculo/1"
                },
                "type": "atividade_veiculo"
            },
            "links": {
            "self": "/api/v1.0/atividades-veiculo/1"
            }
        },
    },
    "id": "6",
    "links": {},
    "type": "veiculo"
}]

I'm trying to show these data on handlebars templates like this {{model.atendimento}} or {{model.atividade}} but it's not rendered corretly. Instead of the value I get a promisse <DS.PromiseObject:ember642>.

I'm not sure what's wrong because I'm using the default JSONAPISerializer and the documentation says it'll be loaded automagically. Does it have something to do with attributes types? Am I supposed to change the payload data?
I have tried to load the related models with RSVP after the main model is loaded but it didn't work.

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles