Skip to content
This repository was archived by the owner on Aug 18, 2018. It is now read-only.

Commit 871abda

Browse files
committed
included collections are saved on store now
1 parent 6124be0 commit 871abda

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-angular-jsonapi",
3-
"version": "0.6.25",
3+
"version": "0.6.26",
44
"description": "JSONAPI library developed for AngularJS in Typescript",
55
"repository": {
66
"type": "git",

src/library/services/cachestore.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,19 @@ export class CacheStore implements ICacheStore {
181181
this.setResource(resource);
182182
tmp.data[resource.id] = { id: resource.id, type: resource.type };
183183

184-
angular.forEach(include, resource_type => {
185-
let ress = <IResource>resource.relationships[resource_type].data;
186-
resources_for_save[resource_type + ress.id] = ress;
184+
angular.forEach(include, resource_type_alias => {
185+
if ('id' in resource.relationships[resource_type_alias].data) {
186+
// hasOne
187+
let ress = <IResource>resource.relationships[resource_type_alias].data;
188+
resources_for_save[resource_type_alias + ress.id] = ress;
189+
} else {
190+
// hasMany
191+
let collection = <ICollection>resource.relationships[resource_type_alias].data;
192+
angular.forEach(collection, (inc_resource: IResource) => {
193+
console.log('hasMany ress need save', inc_resource);
194+
resources_for_save[resource_type_alias + inc_resource.id] = inc_resource;
195+
});
196+
}
187197
});
188198
});
189199
tmp.page = collection.page;

0 commit comments

Comments
 (0)