Created
November 7, 2017 10:29
-
-
Save serenaf/dd18672c77bae32589b966d5f86a0b49 to your computer and use it in GitHub Desktop.
Adding nested comment model
This file contains hidden or 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'; | |
export default DS.Model.extend({ | |
content: DS.attr('string'), | |
user: DS.attr('string'), | |
timeAgo: DS.attr('string'), | |
comments: DS.hasMany('comments', { inverse: null }) | |
}); |
This file contains hidden or 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
ember g model comment content:string user:string timeAgo:string |
This file contains hidden or 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 { computed } from '@ember/object'; | |
export default DS.Model.extend({ | |
title: DS.attr('string'), | |
points: DS.attr('number'), | |
time: DS.attr('unix-date'), | |
timeAgo: DS.attr('string'), | |
url: DS.attr('string'), | |
domain: DS.attr('string'), | |
isInternalLink: computed.empty('domain'), | |
externalUrl: computed('domain', 'isInternalLink', function() { | |
if (this.get('isInternalLink')) { | |
return `https://news.ycombinator.com/item?id=${this.get('id')}` | |
} | |
return this.get('url'); | |
}), | |
comments: DS.hasMany('comment', { async: true }), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment