Skip to content

Instantly share code, notes, and snippets.

@baroquon
Created April 12, 2015 01:51
Show Gist options
  • Save baroquon/22d961282c014259bbb9 to your computer and use it in GitHub Desktop.
Save baroquon/22d961282c014259bbb9 to your computer and use it in GitHub Desktop.
example person.js model
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
// Attributes
first_name: DS.attr('string'),
middle_name: DS.attr('string'),
last_name: DS.attr('string'),
notes: DS.attr('string'),
date_of_birth: DS.attr('date'),
role: DS.attr('string'),
createdAt: DS.attr('date', {
defaultValue: function() { return new Date(); }
}),
// Relationships
parent: DS.belongsTo('user', {
inverse: 'kids',
async: true
}),
kids: DS.hasMany('user', {
inverse: 'parent',
async: true
}),
// Computed Properties
fullName: Ember.computed('first_name', 'last_name', function() {
return this.get('first_name') + ' ' + this.get('last_name');
}),
isParent: Ember.computed('role', function() {
return this.get('role')==='parent';
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment