Last active
August 29, 2015 14:11
-
-
Save tofumatt/5a268a79fb4bd1c24fd2 to your computer and use it in GitHub Desktop.
Trying to do offline data with ember-data
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'; | |
var Checkin = DS.Model.extend({ | |
shout: DS.attr('string'), | |
user: DS.belongsTo('user'), | |
venue: DS.belongsTo('venue'), | |
createdAt: DS.attr('date') | |
}); | |
var User = DS.Model.extend({ | |
firstName: attr('string'), | |
lastName: attr('string'), | |
homeCity: attr('string'), | |
gender: attr('string'), | |
bio: attr('string'), | |
checkins: DS.hasMany('checkin'), | |
accessToken: attr('string'), | |
lastUpdated: attr('date') | |
}); | |
var Venue = DS.Model.extend({ | |
checkins: DS.hasMany('checkin'), | |
name: attr('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
data.response.recent.forEach(function(c) { | |
var user = controller.store.createRecord('user', { | |
id: c.user.id, | |
firstName: c.user.firstName, | |
lastName: c.user.lastName, | |
bio: c.user.bio | |
}); | |
user.save(); | |
var venue = controller.store.createRecord('venue', { | |
id: c.venue.id, | |
name: c.venue.name | |
}); | |
venue.save(); | |
var checkin = controller.store.createRecord('checkin', { | |
id: c.id, | |
user: user, | |
venue: venue, | |
createdAt: moment.unix(c.createdAt)._d, | |
isRecent: true | |
}); | |
checkin.save(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment