vendredi 29 mai 2015

Build dynamic relationship in ember data

I have access to API endpoints to only get, cannot suggest or apply any modifications.

This a sample schema of each api:

var person = DS.Model.extend {
    firstName: DS.attr(),
    lastName: DS.attr()
}

var credit = DS.Model.extend {
    name: DS.attr(),
    personId: : DS.attr()
}

var debit = DS.Model.extend {
    name: DS.attr(),
    personId: : DS.attr()
}

I can get api/person, api/credit, api/debit individually. After fetching the data. I want to map relationship between person and credit/debit similar to this...

var person = DS.Model.extend {
    firstName: DS.attr(),
    lastName: DS.attr(),
    **debits: DS.hasMany('debit'),**
    **credits: DS.hasMany('credit')**
}

How can I accomplish this in ember-data?




Aucun commentaire:

Enregistrer un commentaire