vendredi 26 août 2016

How to give a route a model that contains both sides of hasMany and belongsTo relationship?

I have successfully managed to get this rather ember-unfriendly API result into a parent/child pair of models called 'connector' and 'pin', where the connector is the parent and an array of pins is the children. I have a hasMany('pin') on the connector model and belongsTo('connector') on the pins.

{
    "Connector" : {
        "ConnectorID" : "2015-11-30T16:34:34.217",
        "ConnectorName" : "D38999/20WA98SN"
    },
    "Pins" : [{
            "ConnectorID" : "2015-11-30T16:34:34.217",
            "PinName" : "A"
        }, {
            "ConnectorID" : "2015-11-30T16:34:34.217",
            "PinName" : "B"
        }, {
            "ConnectorID" : "2015-11-30T16:34:34.217",
            "PinName" : "C"
        }
    ]
}

So far, all is well, I think. I am now faced with getting all of the data from both to appear on a route called 'connector'. I can't quite wrap my mind around how to chain the promises so that I can get both

this.get('store').findRecord('connector', params.connector_id);
and 
this.get('store').findRecord('connector', params.connector_id).findAll(???);

It seems like I am fighting an up-hill battle on this relationship. I wish I could just get Ember to treat the array of pins as it would any other singular data type and get/save the data with the record. Am I think of this correctly?




Aucun commentaire:

Enregistrer un commentaire