Created
April 12, 2015 01:51
-
-
Save baroquon/22d961282c014259bbb9 to your computer and use it in GitHub Desktop.
example person.js model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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