Fix handling relationships for V2 API
* we should look for both embedded relationship and relationship key, so in cases like for commit, when there's a full commit data on "commit" property, and only id at "commit_id", we will use commit data * we can't add @type to V2 fallback, because in other places we chack for @type to distinguish V2 and V3 payloads * there's no need to include a record in "included" if there's only a type and an id there
This commit is contained in:
parent
34e53c1034
commit
39a579c9db
|
@ -15,9 +15,9 @@ export default V3Serializer.extend({
|
||||||
let relationship = null;
|
let relationship = null;
|
||||||
let relationshipKey = this.keyForV2Relationship(key, relationshipMeta.kind, 'deserialize');
|
let relationshipKey = this.keyForV2Relationship(key, relationshipMeta.kind, 'deserialize');
|
||||||
|
|
||||||
if (resourceHash.hasOwnProperty(relationshipKey)) {
|
if (resourceHash.hasOwnProperty(key) || resourceHash.hasOwnProperty(relationshipKey)) {
|
||||||
let data = null;
|
let data = null;
|
||||||
let relationshipHash = resourceHash[relationshipKey];
|
let relationshipHash = resourceHash[key] || resourceHash[relationshipKey];
|
||||||
if (relationshipMeta.kind === 'belongsTo') {
|
if (relationshipMeta.kind === 'belongsTo') {
|
||||||
data = this.extractRelationship(relationshipMeta.type, relationshipHash);
|
data = this.extractRelationship(relationshipMeta.type, relationshipHash);
|
||||||
} else if (relationshipMeta.kind === 'hasMany') {
|
} else if (relationshipMeta.kind === 'hasMany') {
|
||||||
|
@ -46,7 +46,6 @@ export default V3Serializer.extend({
|
||||||
resourceHash[key] = attributes[key];
|
resourceHash[key] = attributes[key];
|
||||||
};
|
};
|
||||||
|
|
||||||
resourceHash['@type'] = modelKey;
|
|
||||||
resourceHash['type'] = modelKey;
|
resourceHash['type'] = modelKey;
|
||||||
delete resourceHash[modelKey];
|
delete resourceHash[modelKey];
|
||||||
}
|
}
|
||||||
|
@ -61,15 +60,18 @@ export default V3Serializer.extend({
|
||||||
Object.keys(data.relationships).forEach(function (key) {
|
Object.keys(data.relationships).forEach(function (key) {
|
||||||
let relationship = data.relationships[key];
|
let relationship = data.relationships[key];
|
||||||
let process = function(data) {
|
let process = function(data) {
|
||||||
let type = key.singularize();
|
if(Object.keys(data).sort()+'' !== 'id,type') {
|
||||||
let serializer = store.serializerFor(type);
|
// no need to add records if they have only id and type
|
||||||
let modelClass = store.modelFor(type);
|
let type = key.singularize();
|
||||||
let normalized = serializer.normalize(modelClass, data);
|
let serializer = store.serializerFor(type);
|
||||||
included.push(normalized.data);
|
let modelClass = store.modelFor(type);
|
||||||
if(normalized.included) {
|
let normalized = serializer.normalize(modelClass, data);
|
||||||
normalized.included.forEach(function(item) {
|
included.push(normalized.data);
|
||||||
included.push(item);
|
if(normalized.included) {
|
||||||
});
|
normalized.included.forEach(function(item) {
|
||||||
|
included.push(item);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user