I have an app with a lot of hierarchies of data.
For example, Company
belongsTo IndustryGroup
belongsTo IndustrySector
and, Bookmark
belongsTo Category
. The primary model, Thing
has a many-to-many relationship with both Company
and Bookmark
. So, view might display a Thing
and the three related Companies
and the four user-selected Bookmarks
.
So my models in Ember look like the following to avoid the circular dependencies from my server-side serialization:
// Category
export default DS.Model.extend({
bookmarks: DS.hasMany('bookmark', { async: true })
});
// Bookmark
export default DS.Model.extend({
category: DS.belongsTo('category', { async: false }), // sideloaded from server JSON
things: DS.belongsTo('thing', { async: true })
});
// Thing
export default DS.Model.extend({
// fully sideloaded
bookmarks: DS.hasMany('bookmark', { async: false }),
// fully sideloaded so industry groups and sectors get loaded as well
companies: DS.hasMany('company', { async: false })
});
So, as a general question, is this a good or bad design? It seems to work most of the time for a “Thing-centric” application, but I’ve have run into various problems for views that display the top levels of the hierarchies (e.g. showing all the Companies that are available from an IndustryGroup).