jeudi 30 juillet 2015

EmberJS generic relations

I am looking for an appropriate solution to support generic relations on my EmberJS front-end. On my backend i have a model, let's name it Shipping. this model have an adapter field which is a generic relation to one of the adapters model. i.e. i have 3 different adapters SelfPickupAdapter, CourierAdapter, ZoneAdapter.

model #1

export default DS.Model.extend({
    name: DS.attr('String'),
    address: DS.attr('String'),
    city: DS.attr('String')
});

model #2

export default DS.Model.extend({
    name: DS.attr('String'),
    email: DS.attr('String')
});

model #3

export default DS.Model.extend({
    name: DS.attr('String'),
    address: DS.attr('String'),
    zone: DS.belongTo('Zone')
});

And each of this adapter models should have a way to be linked to the top level model:

export default DS.Model.extend({
    adapter: DS.genericRelation(['SelfPickupAdapter','CourierAdapter','ZoneAdapter']),
    order: DS.belongsTo('Order'),
});




Aucun commentaire:

Enregistrer un commentaire