Support for List of subclasses + base class when calling find()?


#1

Today ember-data is returning a list of the actual type when calling find(). It does not include in the returned list elements from its subclasses. How can we make find() return a list that also includes the elements from subclasses types?

Let’s say we have a base class ‘Animal’ and two subclasses, ‘Dog’ & ‘Fish’, which inherit from it:

App.Animal = DS.Model.extend({
     name: DS.attr('string')
});

App.Dog = App.Animal.extend({
     barkType: DS.attr('string')
});

App.Fish = App.Animal.extend({
     waterType: DS.attr('string')
});

Is there a way to implement the App.Animal.find() method such that the returned List contains objects of type Animals, Dogs and Fish (and not only Animals as it is today?). A bit like Lists/HashMaps in java…

To load the data efficiently, we where thinking of creating JSON as follow when calling /rest/animals:

{
  "animals":[ {id:1, name:"Fred"}, {id:3, name:"Sandy"} ],
  "dogs":[ {id:2, name:"Peter", barkType:"loud"} ],
  "fish":[ {id:4, name:"Jack", waterType:"sea"} ]
}

How could we implement this? Or are we taking a wrong approach here?

Many Thanks!