jeudi 22 septembre 2016

Ember Multitple belongTo relationships not working with JSONAPI

I have the following json api document:

{
  "data": [
    {
      "type": "haves",
      "id": "2708f443-0857-4ae9-9935-9aa4b4e9f721",
      "attributes": {
        "quantity": 1
      },
      "relationships": {
        "card": {
          "data": {
            "type": "cards",
            "id": "3be08f31-3361-404c-9977-23535ed837f3"
          }
        }
      }
    }
  ],
  "included": [
    {
      "type": "cards",
      "id": "3be08f31-3361-404c-9977-23535ed837f3",
      "attributes": {
        "name": "Name"
      },
      "relationships": {
        "set": {
          "data": {
            "type": "sets",
            "id": "0fec70de-02e0-4646-bdcf-f86acea90d23"
          }
        }
      }
    },
    {
      "type": "sets",
      "id": "0fec70de-02e0-4646-bdcf-f86acea90d23",
      "attributes": {
        "name": "Name"
      }
    }
  ]
}

With the following ember models:

// app/models/have.js
export default DS.Model.extend({
  quantity: DS.attr('number'),
  minPrice: DS.attr('number'),
  account: DS.belongsTo('account'),
  card: DS.belongsTo('card')
});

// app/models/set.js
export default DS.Model.extend({
  name: DS.attr('string'),
  cards: DS.hasMany('card')
});

// app/models/card.js
export default DS.Model.extend({
  name: DS.attr('string'),
  set: DS.belongsTo('set'),
  haves: DS.hasMany('have')
});

And a custom inflector rule:

inflector.irregular('have', 'haves');

When I load the json document with this structure though, I can't seem to do something like have.card.set.name in my template when I iterate this jsonapi document. I'm guessing my jsonapi structure is incorrect. What am I missing? I don't get any errors in my chrome console or in the ember server running. When I load Ember Inspector, I see the set model under Data.




Aucun commentaire:

Enregistrer un commentaire