Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kumkanillam/ee24c80509b24a5b58a67aeb3275819e to your computer and use it in GitHub Desktop.
Save kumkanillam/ee24c80509b24a5b58a67aeb3275819e to your computer and use it in GitHub Desktop.
ember not recognizing plural type in payload
import Ember from 'ember';
export default Ember.Route.extend({
init() {
this._super(...arguments);
$.mockjax({
url: '/api/mock',
responseText: {
"data":
{
"id":"2506","type":"order",
"attributes":{"paid-amount":"109.29","net-amount-received":"105.0","total-fee-amount":"4.29","paid":true,"payment-method":"Stripe","host-name":"SwingIN 2016","host-url":"//swing.vhost/swingin2016","created-at":"2016-06-19T20:30:53.218-04:00","payment-received-at":"2016-06-19T20:32:01.000-04:00","total-in-cents":10929,"stripe-refunds":[{"amount":2075,"created":1466392180,"status":"succeeded"}],"current-paid-amount":"88.54","current-total-fee-amount":"3.69","current-net-amount-received":"84.85"},
"relationships":{
"order-line-items":{
"data":[
{"id":"3313","type":"order-line-item"},
{"id":"3314","type":"order-line-item"}]},
"host":{"data":{"id":"23","type":"events"}},
"attendance":{"data":{"id":"1814","type":"event-attendances"}},
"pricing-tier":{"data":{"id":"57","type":"pricing-tiers"}}}}
}
});
},
model() {
return $.getJSON('/api/mock');
},
actions: {
refreshStripe() {
console.log('action called');
Ember.$.ajax({
url: '/api/mock',
type: 'GET'
}).then(data => {
this.get('store').push(data);
}, error => {
let json = JSON.parse(error.responseText);
console.log(json);
});
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
host: belongsTo('host'),
orders: hasMany('order')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
import Attendance from './attendance';
export default Model.extend(Attendance, {
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
import Host from './host';
export default Model.extend(Host, {
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
orders: hasMany('orders')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
order: belongsTo('order')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
host: belongsTo('host', { polymorphic: true }),
orderLineItems: hasMany('order-line-item'),
attendance: belongsTo('attendance', { polymorphic: true }),
pricingTier: belongsTo('pricing-tier'),
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
orders: hasMany('order'),
event: belongsTo('event')
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{model}}
<button {{action 'refreshStripe'}}>Send Ajax</button>
{
"version": "0.4.8",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0",
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment