Polymorphic types in ember data


#1

The REST API I’m using with ember data has an ‘endpoints’ resource. This returns an array of models like any other resource but with a ‘type’ property for each item.

These models have common properties of an endpoint (like name, shortNumber, etc…), but they also have common property’s that are relevant to that type only (timeout, destination, etc…).

How can I handle this data with ember data? I need to be able to do a: store.find(‘endpoint’, {type: “phone”}) in routes as well as querying the data as a whole. I’m not sure if I would have to map the data into separate models in the store or a single one with different subclasses models?

Hope you guys have some ideas for me. Here is the API I’m referring to: https://developer.sipcentric.com/api/v1/#endpoints

Sample data of the response from the base of the ‘/endpoints’ resource:

{
  "totalItems" : 25,
  "pageSize" : 2,
  "page" : 1,
  "items" : [ {
    "type" : "ivr",
    "id" : "101",
    "uri" : "http://pbx.sipcentric.com/api/v1/customers/345/endpoints/101",
    "created" : "2011-06-23T01:51:33.000+0000",
    "shortNumber" : "001",
    "name" : "Main IVR",
    "timeout" : 0
  }, {
    "type" : "queue",
    "id" : "41",
    "uri" : "http://pbx.sipcentric.com/api/v1/customers/345/endpoints/41",
    "created" : "2010-12-21T08:36:04.000+0000",
    "shortNumber" : "010",
    "name" : "General Queue",
    "maxWait" : 60
  } ]
}