Belongs to relation ( SOLVED )

Hi all,

In a standard belongsTo relation ember will use the “id” from the response of the parent request to call the defined belongsTo request, right?

This is my current use case. Model: “token”

export default DS.Model.extend({
    agent: DS.belongsTo('agent', { async: true })
});

First request:

http://localhost:4202/tokens/b7e14f81-0ff7-4b6b-b150-898b21e12042

First response:

{
    "token":{
        "id":"b7e14f81-0ff7-4b6b-b150-898b21e12042", 
        "agent":"test.agent@test.com"
    }
}

Now the belongsTo relation will be called from ember with this request:

http://localhost:4202/agents/test.agent@test.com

The response of the agent request is now:

{
    "agent":{
        "id":"1",
        "firstname":"Test",
        "lastname":"Agent",
        "email":"test.agent@test.com"
    }
}

Now ember logs a warning in the console that my response agent id is “1” instead of “test.agent@test.com”. I don’t understand why … It’s possible to define another property for belongsTo requests? ( I believe that I do not understand this concept in ember complete how ember is working intern. )

Best regards, Mario

In a standard belongsTo relation ember will use the “id” from the response of the parent request to call the defined belongsTo request, right?

Yes. You are requesting the agent id test.agent@test.com

http://localhost:4202/agents/<id>
http://localhost:4202/agents/test.agent@test.com

so the backend response should be

{
    "agent":{
        "id":"test.agent@test.com",
        "firstname":"Test",
        "lastname":"Agent",
        "email":"test.agent@test.com"
    }
}

Thank you again … :slight_smile:

Mario