Search code examples
ember.jsember-data

How to subclass or inherit a model from another model using ember-data


Let's say my rails models look like this:

class SalesRelationship < ActiveRecord

end

Which is inherited by crossSell like this:

class crossSell < SalesRelationship 

end

How do I show this inheritance relationship in ember-data. What is the best practise for this:

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

Can I create a subclass called 'crossSell', like this

crossSell = App.salesRelationship({
    productName: DS.attr('string')
});

or like this

 App.salesRelationship.crossSell  = DS.Model.extend({
    productName: DS.attr('string')
  });

Solution

  • Pretty close, you can just extend SalesRelationship.

    App.CrossSell = App.SalesRelationship.extend({
      productName: DS.attr('string')
    })