Customizable query for async requests
I have a model:
Floor = DS.Model.extend({
tables: DS.hasMany('table', {async: true})
});
When I query tables I would really like to send a single GET request with floor_id
as a parameter instead of multiple requests for each table with table_id
as a param.
For now I use an intermediate TableSet
object as a work around. It works nicely but requires extra effort to keep it in sync when tables get added/removed.
It would be very helpful if I can specify the way I query async relationship.
probably something like this:
Floor = DS.Model.extend({
tables: DS.hasMany('table', {async: true, query: 'tablesQuery'}),
tablesQuery: function(){
return this.get('store').find('table', { floor_id: this.get('id') } );
}
});
Check if async relationship is loaded.
There is currently no way I can find out whether async relationship is actually loaded. Here is an example how I would I use the isLoaded flag:
Floor = DS.Model.extend({
auditSet: DS.belongsTo('auditSet', {async: true}),
auditSetChangedOnServer: function() {
if this.get('auditSet.isLoaded') {
this.get('auditSet').then(function(as){ return as.reload() });
}
}
});