Can a Model belongTo a number of other models from a single property?

In this exmaple case, a single Ball either belongsTo Football, or it belongsTo Soccer.

App.Football = DS.Model.extend({
    name: DS.attr('string'),
    balls: DS.hasMany('balls', { inverse: 'sport' })
});
App.Soccer = DS.Model.extend({
    name: DS.attr('string'),
    balls: DS.hasMany('balls', { inverse: 'sport' })
});
App.Ball = DS.Model.extend({
    color: DS.attr('string'),
    sport: DS.belongsTo('No idea what goes here', { inverse: 'balls' }),
    sportType: 'No idea what goes here'
});

Is there a way to represent this in Ember.js? And would the Ball need a sportType to differentiate between store.find('football', 1) and store.find('soccer', 1)?

It sounds like you are referring to polymorphic associations.

https://github.com/emberjs/data/pull/750

This topic was automatically closed after 3 days. New replies are no longer allowed.