Firstly, I will be using ember-cli for development and I get JSON from the server in embedded format:
Single Objects
{
"id" : 1,
"name" : "Tom",
"surname" : "Smith",
"address" : {
"id" : 2,
"street" : "23",
"city" : "...",
...
}
}
Arrays
[
{
"id" : 1,
"name" : "Tom",
"surname" : "Smith",
"address" : {
"id" : 2,
"street" : "23",
"city" : "...",
...
}
},
{
"id" : 2,
"name" : "Tom",
"surname" : "Smith",
"address" : {
"id" : 4,
"street" : "23",
"city" : "...",
...
}
},
...
]
I have worked out how to append the prefix onto each payload using the following in RestAdapter.
export default DS.RESTSerializer.extend({
extract : function(store, type, payload, id, requestType) {
var typeKey = type.typeKey,
typeKeyPlural = typeKey.pluralize();
//Add name of model to payload as expected by ember data
var modelName = Array.isArray(payload) ? typeKeyPlural : typeKey;
var normalizedPayload = {};
normalizedPayload[modelName] = payload;
return this._super(store, type, normalizedPayload, id, requestType);
},
)}
I have searched around all over the place and can see all these different ways of embedding records in ember.
The official docs say to us the DS.EmbeddedRecordsMixin Class. But this would mean I would need to create a DS.ActiveModelSerializer for every single model, I would rather define the attribute in the model itself {embedded : "always"}. http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html
This actually sort of worked but is obviously old because the parameters have since changed. It is a bit of a hack in my opinion. http://mozmonkey.com/2013/12/serializing-embedded-relationships-ember-data-beta/
There is this project, but no docs or example of how to get it working. https://github.com/pixelhandler/ember-data-extensions
All in all I am very confused.