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


#1

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)?


#2

It sounds like you are referring to polymorphic associations.


#3

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