jeudi 18 août 2016

Ember Data Serialize with link

Using Ember 2.7.1 (and I am new to Ember)

I fetch from an external API which returns reference/relationship to a model as follows. The elements contains the link to the specific basket and not the typical basket object. The link is available in uri attribute

{
      "elements": [
        {
          "type": "Link",
          "title": "48MKzg7EVNAAAAFVux0natwM",
          "uri": "My-Site/-/baskets/48MKzg7EVNAAAAFVux0natwM"
        }
      ],
      "type": "ResourceCollection",
      "name": "baskets"
    }

Basket JSON

{
  "name": "basket",
  "type": "Basket",
  "invoiceToAddress": {
        //...attributes of invoiceToAddress...
  },
  "externalOrderReferenceID": "",
  "shippingBuckets": [
    {
        //...one or many shippingBuckets 
    }
  ],
  "dynamicMessages": [],
  "totals": {
     //...attributes of totals...
  },
  "multipleShippmentsSupported": true,
  "purchaseCurrency": "USD",
  "id": "48MKzg7EVNAAAAFVux0natwM"
}

Model: //app/models/basket.js

export default DS.Model.extend({
    multipleShippmentsSupported: DS.attr(),
    purchaseCurrency: DS.attr(),
    externalOrderReferenceID: DS.attr()
});

The direct route to get a basket works. this.get('store').findRecord('basket', '48MKzg7EVNAAAAFVux0natwM');

How do I best write a model + serializer where a findAll('basket') gets me the full details of the one basket which is available in the 'elements'?

(I understand that theoretically there can be more that one basket )

I have used various combinations of RESTSerializer, JSONSerializer tips that were available in guides, tutorials but I am unable to get this to load correctly




Aucun commentaire:

Enregistrer un commentaire