Skip to content

Instantly share code, notes, and snippets.

@jakiestfu
Created January 25, 2017 23:20
Show Gist options
  • Save jakiestfu/0252f1949eae38c787723a6e55df268f to your computer and use it in GitHub Desktop.
Save jakiestfu/0252f1949eae38c787723a6e55df268f to your computer and use it in GitHub Desktop.
New Twiddle
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";
import PaymentMethod from "models/payment-method";
export default PaymentMethod.extend({
ccNumber: attr('number'),
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
import Ember from 'ember';
import PaymentMethod from "./payment-method";
export default PaymentMethod.extend({
email: attr('string'),
capsEmail: Ember.computed('email', function () { return this.get('email').toUpperCase(); }),
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
user: belongsTo('user'),
foo: 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('string'),
paymentMethod: hasMany('payment-method', { polymorphic: true }),
});
import Ember from 'ember';
export default Ember.Route.extend({
model(params, transition) {
const store = this.get('store');
const paymentMethod = store.createRecord('payment-method', {
payment_method_type: 'payment-method-paypal',
email: '[email protected]'
});
const user = store.createRecord('user', {
name: 'Jacob',
paymentMethod: [ paymentMethod ],
});
console.log(user.get('paymentMethod.firstObject.capsEmail')); // Expected: "[email protected]"
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment