Is it possible to have polymorphic Ember Data Models?

I ended up doing this:

normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
    const res = this._super(store, primaryModelClass, payload, id, requestType);

    for (let i = 0; i < res.data.length; i++) {
      if (res.data[i].attributes.role === Roles.STUDENT) {
        res.data[i].type = 'student';
      }
      if (res.data[i].attributes.role === Roles.TEACHER) {
        res.data[i].type = 'teacher';
      }
    }

    return res;
  },

Not sure it’s the most elegant way but it seems to be invoking the right modal each time.

However, if I want to return all persons inside a person key, looks like I need to do something like this (from your previous responses) which I’m not too excited about.

ie.

let persons = [...this.store.peekAll('teacher'), ...this.store.peekAll('student')];

Either way, thanks for the help!

2 Likes