Skip to content

Instantly share code, notes, and snippets.

@alexdiliberto
Created May 7, 2020 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdiliberto/378a41b728ba6c95777d6041151697f3 to your computer and use it in GitHub Desktop.
Save alexdiliberto/378a41b728ba6c95777d6041151697f3 to your computer and use it in GitHub Desktop.
REST Adapter With Sideloading
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
export default function() {
window.server = this;
this.get('/cartItems', function (schema, request) {
return {
"cart-items": [
{
"cart": "0048f8cc-ef50-11e7-8337-76502ffc62f3",
"id": "ROVE949352B",
"personalization": [],
"prices": {
"price": 74.95,
"totalPrice": 74.95
},
"product": 4464,
"quantity": 1,
"skuid": "ROVE949352B",
"variantCodes": [],
"variantData": []
},
{
"cart": "0048f8cc-ef50-11e7-8337-76502ffc62f3",
"id": "BLK4226",
"personalization": [],
"prices": {
"origprice": 0,
"price": 60,
"totalPrice": 60
},
"product": 4502,
"quantity": 1,
"skuid": "BLK4226",
"variantCodes": [],
"variantData": []
}
],
"products": [
{
"id": 4464,
"images": {
"image": "tristan-irish-watch.jpg",
},
"name": "Watch - Gold Plated Watch",
"prices": {
"price": 74.95
},
"skuid": "ROVE949352B"
},
{
"id": 4502,
"images": {
"image": "BLK4226.jpg"
},
"name": "Serving Bowl",
"prices": {
"origprice": 0,
"price": 60
},
"skuid": "BLK4226"
}
]
}
});
};
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
cart: belongsTo('cart'),
product: belongsTo('product', { async: true }),
skuid: attr('string'),
quantity: attr('number'),
personalization: attr(''),
variantCodes: attr(''),
variantData: attr(''),
prices: attr('')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
cart: attr('string'),
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr(''),
skuid: attr(''),
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').findAll('cart-item', { include: 'products' });
}
});
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
// normalizeArrayResponse() {
// let res = this._super(...arguments);
// console.log('normalized array response:', res);
// return res;
// }
});
<h1>Welcome to {{appName}}</h1>
<ul>
{{#each model as |item|}}
<li>{{item.id}}</li>
<ul>
<li>{{item.product.id}}</li>
<ul>
<li>{{item.product.name}}</li>
<li>{{item.product.skuid}}</li>
</ul>
</ul>
{{/each}}
</ul>
{
"version": "0.13.0",
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3",
"ember-cli-mirage": "0.4.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment