Skip to content

Instantly share code, notes, and snippets.

@smithcommajoseph
Created August 26, 2014 15:32
Show Gist options
  • Select an option

  • Save smithcommajoseph/4dfd21c8bf23519adf0a to your computer and use it in GitHub Desktop.

Select an option

Save smithcommajoseph/4dfd21c8bf23519adf0a to your computer and use it in GitHub Desktop.
Ember data working sideloaded data example
// lookup the store
store = OC2.__container__.lookup('store:main')
// Models
OC2.Color = DS.Model.extend({
color: DS.attr(),
foos: DS.hasMany('foo'),
colors: DS.hasMany('color')
});
OC2.Foo = DS.Model.extend({
name: DS.attr()
});
// data
t = {
colors:[
{
id: 1,
color: "red",
foos:[1,2],
colors: [2, 3]
},
{
id: 2,
color: "green",
foos:[3,4],
colors: [3]
},
{
id: 3,
color: "blue",
foos:[5,6],
colors: [1,2]
}
],
foos: [
{
id:1,
name:'something 1'
},
{
id:2,
name:'something 2'
},
{
id:3,
name:'something 3'
},
{
id:4,
name:'something 4'
},
{
id:5,
name:'something 5'
},
{
id:6,
name:'something 6'
}
]
};
// push color data into the store
store.pushMany('color', t.colors);
// push foo data into the store
store.pushMany('foo', t.foos);
// get a color
color = store.getById('color', 1);
// lookup foos
color.get('foos');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment