Skip to content

Instantly share code, notes, and snippets.

@tofumatt
Last active August 29, 2015 14:11
Show Gist options
  • Save tofumatt/5a268a79fb4bd1c24fd2 to your computer and use it in GitHub Desktop.
Save tofumatt/5a268a79fb4bd1c24fd2 to your computer and use it in GitHub Desktop.
Trying to do offline data with ember-data
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')
});
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