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')
});
Pretty close, you can just extend SalesRelationship.
App.CrossSell = App.SalesRelationship.extend({
productName: DS.attr('string')
})
In Ember 2.7 it can be done like this. Assume you have a Person
class and wish to inherit from it to make an Employee
for a status field (like hired, retired, fired on-leave etc)
app/models/person.js
import DS from 'ember-data';
export default DS.Model.extend({
firstName: DS.attr(),
lastName: DS.attr(),
fullName: Ember.computed('firstName', 'lastName', function() {
return `${this.get('lastName')}, ${this.get('firstName')}`;
});
app/models/employee.js
import DS from 'ember-data';
import Person from './person';
export default Person.extend({
status: DS.attr(),
statusCode: DS.attr(),
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With