Skip to content

Search for relationships inside the data object. #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Classes/JSONAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ - (void)inflateWithDictionary:(NSDictionary*)dictionary {
// Parses included resources
id included = dictionary[@"included"];
NSMutableDictionary *includedResources = [[NSMutableDictionary alloc] init];
// Adding the resources to the included attribute
for (NSObject <JSONAPIResource> *resource in _resources) {
JSONAPIResourceDescriptor *desc = [resource.class descriptor];

NSMutableDictionary *typeDict = includedResources[desc.type] ?: @{}.mutableCopy;
typeDict[resource.ID] = resource;

includedResources[desc.type] = typeDict;
}

if ([included isKindOfClass:[NSArray class]] == YES) {
for (NSDictionary *data in included) {

Expand Down
2 changes: 1 addition & 1 deletion Classes/JSONAPIResourceParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ + (NSArray*)relatedResourcesFor:(NSObject <JSONAPIResource>*)resource {
id value = [resource valueForKey:key];
if ([value isKindOfClass:[NSArray class]]) {
[related addObjectsFromArray:value];
} else {
} else if (value) {
[related addObject:value];
}
}
Expand Down