Skip to content

Instantly share code, notes, and snippets.

@sfncook
Created August 21, 2015 03:57
Show Gist options
  • Save sfncook/e96a003dc057feaa41ee to your computer and use it in GitHub Desktop.
Save sfncook/e96a003dc057feaa41ee to your computer and use it in GitHub Desktop.
Code Sample
var Incident = store.defineResource({
name: 'incident',
relations: {
hasMany: {
sector: {
foreignKey: 'incident_id',
localField: 'sectors'
}
}
}
});
var Sector = store.defineResource({
name: 'sector',
relations: {
hasMany: {
unit: {
foreignKey: 'sector_id',
localField: 'units'
}
},
belongsTo: {
incident: {
localKey: 'incident_id',
localField: 'incident'
}
}
}
});
// var Unit = store.defineResource('unit');
var Unit = store.defineResource({
name: 'unit',
relations: {
belongsTo: {
sector: {
localKey: 'sector_id',
localField: 'sector'
}
}
}
});
Incident.find(1).then(function(incident) {;
console.log('incident: ', incident);
console.log('sectors[0]: ', incident.sectors[0]);
console.log('units[0]: ', incident.sectors[0].units[0]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment