# More flexible async relationship

**URL:** <https://discuss.emberjs.com/t/more-flexible-async-relationship/7334>\
**Category:** Ember Data\
**Created:** [February 17, 2015, 4:26am UTC](https://discuss.emberjs.com/t/more-flexible-async-relationship/7334 "2015-02-17T04:26:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arkadiyk](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/arkadiyk/32/5258_2.png) [@arkadiyk](https://discuss.emberjs.com/u/arkadiyk)\
**Post date:** [February 17, 2015, 4:26am UTC](https://discuss.emberjs.com/t/more-flexible-async-relationship/7334/1 "2015-02-17T04:26:39Z")

</div>

## Customizable query for async requests

I have a model:

```javascript
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:

```javascript
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:

```javascript
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() });
    }  
  }
});

```

---

<div class="post-metadata">

**Author:** ![bakerac4](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/bakerac4/32/10593_2.png) [@bakerac4](https://discuss.emberjs.com/u/bakerac4)\
**Post date:** [February 17, 2015, 2:16pm UTC](https://discuss.emberjs.com/t/more-flexible-async-relationship/7334/2 "2015-02-17T14:16:59Z")

</div>

Im not sure what adapter you are using, but the REST or ActiveModelAdapter there is a property called coalesceFindRequests. It will collect all your GET calls into one call, but it will still be based upon the table IDs, not the floor ID. [RESTAdapter - 4.6 - Ember API Documentation](http://emberjs.com/api/data/classes/DS.RESTAdapter.html#property_coalesceFindRequests)

The other option you can do is use the ‘Links’ hash. Essentially instead of passing down IDs, your passing down where to find the information that ember needs. Check it out here [Getting Started with Ember Data · Andy Crum](http://andycrum.com/2014/06/02/getting-started-with-ember-data/) (just look for ‘links hash’)
