Embedded record problems

following that instructions: https://github.com/emberjs/data/blob/master/TRANSITION.md#embedded-records

receiving this json from the server

{
    "installazioni": [{
        "id": "25",
        "descrizione": "Installazione 25",
        "prodotto_id": "19",
        "venditore_id": "0",
        "created_at": "2013-09-25 17:10:02",
        "updated_at": "2013-09-26 14:45:44",
        "prodotto": {
            "id": "19",
            "nome": "Prodotto 19",
            "descrizione": "",
            "installabile": "0",
            "created_at": "2013-09-25 17:10:44",
            "updated_at": "2013-09-25 17:10:44"
        }
    }]
}

I’m developing this serializer

Wus.InstallazioneSerializer = DS.RESTSerializer.extend({
    extractSingle: function(store, type, payload, id, requestType) {
        var prodotto = payload.installazione.prodotto,
            prodottoId = prodotto.mapProperty('id');

        payload.prodotto = prodotto;
        payload.installazione.prodotto = prodottoId;

        return this._super.apply(this, arguments);
    }
});

but I receive that errors on the console

Error while loading route: TypeError {} ember.js:394

Uncaught TypeError: Cannot call method 'toString' of undefined ember-data.js:2354

To be true i receive that errors also without serializer… so, any ideas of where can be the problem? :blush:

thanks in advance :wink:

I just stumbled upon the same issue when updating to ember-data 1.0.0.beta2. I solved it by modifying the payLoad like you did, but I see two problems with your code:

  • You’re using extractSingle instead of extractArray which is the correct function to overwrite when receiving a collection.
  • ember-data needs to know how to map between installazioni (plural) and installazione (singular). You can probably tell ember to map properly between these two words, but I’m not sure how and where.