How to specify a query for async association (ActiveModel)


#1

I suddenly had an epiphany about why code I have isn’t working. I have a model with an async: true relationship to an collection of related items.

My serializer:

class ProfileGroupSerializer << ActiveModel::Serializer
  attributes :id, :name
end

class TagSerializer << ActiveModel::Serializer
  attributes :id, :name
  has_one :profile_group
end

Ember models:

export default DS.Model.extend({
  name:     DS.attr('string'), 
  tags:     DS.hasMany('tags', { async: true })
});

export default DS.Model.extend({
  name:     DS.attr('string'),
  profileGroup: DS.belongsTo('profileGroup', { async: false });
});    

So displaying a Tag works, of course. The ProfileGroup is side-loaded.

But, I guess I don’t fully understand how ProfileGroup builds it’s association to Tags other than via a side-effect of tags being queried? I assumed there would be a REST call whenever I tried profileGroup.get('tags').

Anyway… the more I thought about it the more it as apparent it couldn’t work. There’s no REST endpoint defined that automatically queries for tags given a ProfileGroup ID. That would be easy enough to setup, of course, but how do I specify a mechanism for ProfileGroup to get all of it’s associated children?